It's all the same. If you declare it with using statements then it makes it MUCH cleaner and a lot less cluttered. Some namespaces can get really big and in depth, so being able to declare using statements is a huge advantage. I would much rather see something
like this:
using MyClass.DAL.UnderlyingAccess.SomeSubSection.NewAdditions.v3012.MyObjects;
public class MyClass
{
public MyCoolObject theThing;
}
than this:
public class MyClass
{
public MyClass.DAL.UnderlyingAccess.SomeSubSection.NewAdditions.v3012.MyObjects.MyCoolObject theThing;
}
Thank you very much for take your time and answer me Scott. I really appreciate it. However this not the answer that I am looking for those link showed how use it and the alias, but I am looking for a comparison in the use relate to the the performace and
the compiler if theri is a difference. I think is the same but I am not sure about it and I havent found anything on internet with a diffrence everybody show the two way to do and verybody refers to better readability but I want to know if that create something
different for the compiler :)
There is no difference at all. Essentially when the Linking process of the compiler begins it will load the references the same way as if you wrote them all in-line. That's kind of like asking if the compiler see's a difference between:
private void someFunction {
}
and
private void someFunction
{
}
The brackets are in a different position as far as the raw cs file is concerned but it turns into a whole different monster at compile time.
Scott was here...
Marked as answer by sinedyip on Dec 19, 2012 01:44 AM
Just wanted to add the only difference I can think of
If you have code which is already working and then add another #using then your code may no longer compile because you may introduce a namesapce collision.
sinedyip
Member
308 Points
154 Posts
Differences regard used #using Project.Classes or declare and object
Dec 18, 2012 09:27 PM|LINK
Hi,
I was working the other day and I was thinking if there is a real difference between use the directive #using MyNamespace.Classe
and the Create my object on code behind like that
Myclass myObject = new ...
or use
MyNamespace.Classe.Myclass my Object = new ...
Is there advantage or disadvante in those methods?
N_EvilScott
Star
8179 Points
1466 Posts
Re: Differences regard used #using Project.Classes or declare and object
Dec 18, 2012 09:33 PM|LINK
It's all the same. If you declare it with using statements then it makes it MUCH cleaner and a lot less cluttered. Some namespaces can get really big and in depth, so being able to declare using statements is a huge advantage. I would much rather see something like this:
using MyClass.DAL.UnderlyingAccess.SomeSubSection.NewAdditions.v3012.MyObjects; public class MyClass { public MyCoolObject theThing; }than this:
public class MyClass { public MyClass.DAL.UnderlyingAccess.SomeSubSection.NewAdditions.v3012.MyObjects.MyCoolObject theThing; }sinedyip
Member
308 Points
154 Posts
Re: Differences regard used #using Project.Classes or declare and object
Dec 19, 2012 12:03 AM|LINK
Thank you Scott I was thinking the same. Do you have some reference or ducmentation about it?
N_EvilScott
Star
8179 Points
1466 Posts
Re: Differences regard used #using Project.Classes or declare and object
Dec 19, 2012 12:08 AM|LINK
http://msdn.microsoft.com/en-us/library/sf0df423(v=vs.80).aspx
http://stackoverflow.com/questions/1035073/whats-this-c-sharp-using-directive
Just google for "C# Using Directive" or "C# Using Alias" and you'll find quite a bit.
sinedyip
Member
308 Points
154 Posts
Re: Differences regard used #using Project.Classes or declare and object
Dec 19, 2012 12:19 AM|LINK
Thank you very much for take your time and answer me Scott. I really appreciate it. However this not the answer that I am looking for those link showed how use it and the alias, but I am looking for a comparison in the use relate to the the performace and the compiler if theri is a difference. I think is the same but I am not sure about it and I havent found anything on internet with a diffrence everybody show the two way to do and verybody refers to better readability but I want to know if that create something different for the compiler :)
N_EvilScott
Star
8179 Points
1466 Posts
Re: Differences regard used #using Project.Classes or declare and object
Dec 19, 2012 12:23 AM|LINK
There is no difference at all. Essentially when the Linking process of the compiler begins it will load the references the same way as if you wrote them all in-line. That's kind of like asking if the compiler see's a difference between:
private void someFunction {
}
and
private void someFunction
{
}
The brackets are in a different position as far as the raw cs file is concerned but it turns into a whole different monster at compile time.
Paul Linton
Star
13403 Points
2531 Posts
Re: Differences regard used #using Project.Classes or declare and object
Dec 19, 2012 02:11 AM|LINK
Just wanted to add the only difference I can think of
If you have code which is already working and then add another #using then your code may no longer compile because you may introduce a namesapce collision.