Hi everyone,
I have some doubts about the usage necessity of using keywords.
Instead of using this keyword, it is enough to only add the packages into our Assembly(DLL files), so inspite of this, why do some programmer do both of them(add the packages into Assembly and also use using keywords for these packages).
Thanks,
Mert
I have some doubts about the usage necessity of using keywords.
Instead of using this keyword, it is enough to only add the packages into our Assembly(DLL files), so inspite of this, why do some programmer do both of them(add the packages into Assembly and also use using keywords for these packages).
Thanks,
Mert

using keywords
CapitanMiki
I'll show you with an example why the keyword using is useful:
//not using the keyword "using"
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
System.Windows.Forms.Panel panel = new System.Windows.Forms.Panel();
System.Windows.Forms.TextBox textbox = new System.Windows.Forms.TextBox();
// using the keyword "using"
using System.Windows.Forms;
Form form = new Form();
Panel panel = new Panel();
TextBox textbox = new TextBox();
I think the second version is much more user friendly and easier to read.
PS: the using keyword can cause some problems if you have different classes/types in with the same name but in different namespaces.. of course, in this case you'd to resolve the ambiguities because the compiler can't solve which object/type you want to use.
Keith Buik
Again thanks very much for your all helps.
Best wishes,
Mert(JavaBoy)
SeeBee
Oh, I did not know this. It is really a magnificient advantage of Visual Studio.NET 2005 .
Menawhile I used 2005 express version, is this property valid for Visual Studio.NET 2005 express edition
I would like to ask that what you meant explicilty by saying smart tag
Best wishes,
Mert(JavaBoy)
Mike Bouck
Last letter of typed word has a magenta colored underline and when you go with mouse over that position then under that point a dropdownlist is shown with all posible using that you can add and if you click on that, using is automaticaly added. Or when you see that underline you can just click Shift + Ctrl + F10.
basmar
*grin* I'm glad you understood him right away, I typed a long answer about using statements within C# code before it dawned on me....
Alexey Monastyrsky
Thanks very much for your reply again and now I think I kept the idea.
So if we want to use any class; (for instnace; Point class) we must add its DLL(assembly) which is called System.Drawing. and we can do this by clicking adding reference on the project. Besides, we also should not use using keywords for Point class, is not itMohammadSamara
Once you've added the dll, you have access to the Point class, and you can choose to put using System.Drawing, or to put System.Drawing.Point in your code, it's up to you.
Carlos Figueroa
Thanks,
Mert(JavaBoy)
AdamCCC
Regardless of your having added a package to your assembly, you need either a using statement, or a complete namespace every time you use an object. You're free to type System.IO.File.Exists instead of a using System.IO and then have access to the File class directly, but generally speaking, if I use a package, I'll also scope it's namespace so I can use it's elements in a more concise syntax.
I should add that if you DONT add an assembly to your project, no amount of using statements will give you access to it's contents.
bobthebob
In fact, we answered this.
Adding the assemblies makes the dlls available to your code. The using statements make it easier to use the objects in those namespaces. A dll can contain more than one namespace, or contain a namespace that also exists in other dlls. There is no 1:1 correlation here, and as I said, if you don't add the dlls, the compiler wii reject the 'using' statements, as they will not be there to use.
abrewerton
Currently visual studio doesn't add using row automatically when you add reference. There is many reason for that. Imagine big project with several tens of referenced assemblies. So in every class file you will have several tens of using statements that are not neccessary for every file. In VS 2005 you have a great feature. That is when you first start to use some class or method for which you don't have a using statement but you also don't type full namespace, then VS, automatically shows a smart tag and if you click it will add using statement, so from that moment you can continue. For example if you try to type
File.
and if you don't have a using System.IO; statement, but you have a reference added, then a smart tag will help you to add using statement, so you can continue with typing.
There is of course some comercial tools that make this process even quicker and simpler.