This is such a dumb question, but I can’t figure out the lingo to ask Google.
In Java if I wanted to import all subclasses I would use something like
java.util.*
And all of util would be imported.
Firstly, what is the proper lingo for what I’m doing in C# so I can start using Google more effectively. Am I importing namespaces? Libraries? Subclasses? (Can you tell I’m new at this?)
Secondly, since I’m here, how is this accomplished in C#?
PS- I did click on every related question stackOverflow threw at me to see if the answer would pop up. No luck. I’m simply without words to describe what I’m looking for. The example should do just fine but… Anyone who can take a moment to either explain the lingo to me or perhaps simply point me at something that can (in a nutshell, I have a couple books for the long haul) that would be great.
Firstly, let’s differentiate between assembly references and namespaces.
Assemblies are what you add references to in your c# project, they are the libraries that contain the actual classes you need, usually found as DLL files. The .net framework contains many such assemblies, and Visual Studio will try to reference the most commonly used ones in your project (e.g. for a WinForms project it will automatically add a reference to
System.Drawing.dll).Namespaces are logical partitions of the classes in an assembly.
Once you reference an assembly in the project, all classes in all namespaces are available for use, if you provide their full name.
This is where the
usingdirective comes in.It is simply syntactic sugar for not having to write very long names all the time.
For example, assuming your project references the
System.Drawing.dllassembly, you would have to qualify a class from this assembly using it’s full name, for exampleBecause this is tiresome and bloats the code, if you start your
.csfile withyou could then instantiate a class using just the name
BitmapData.This will be true only for the
.csfile in which you added theusingdirective, not for the whole project.Also, it’s important to note that
usingone namespace does not bring in all nested namespaces, you have tousingeach one individually.