Some concepts of beginners are often confused. The following questions are very representative.
| Source |
Http://community.csdn.net/Expert/topic/4052/4052154.xml? Temp =. 9977991. |
| Problem |
Ask: What do you mean by namespaces in C # and ASP. NET? What is equivalent to C, C ++, or Delphi? What is the use of a namespace? Thank you. |
Here I will only explain.. Net and the relationship with the Assembly. C does not have this concept. c ++'s namespace principles and functions are basically the same as those in C #. Delphi, Haha, I have never touched it :). Well, let's get started.
The namespace allows us to logically organize related types,
This makes it easy for us to locate a type.. For example, if the namespace is not introduced into a queue, Write System as follows. collections. queue q = new system. collections. queue (); what about introducing namespaces? Write using system in this way. collections; // introduce queue q = new Queue (); for editing, the namespace only adds symbols separated by dots before the type name. this makes the name of a type longer and more unique.
Two identical classes conflict in the same namespace.,
If different namespaces have the same type,
It also produces ambiguity., Like a directory in windows, the same directory cannot have files of the same name, but different directories can. if you need to use it, you can use the full name (system. collections. queue), or using sysqueue = system. collections. queue; in case of type conflict, all namespaces should strictly follow the naming rules. Generally
Company
.
Product.
LibraryNote that the C # using directive instructs the compiler to try to add different prefixes to the type name until a match is found. The namespace is only logical, A real type is in a collection. When you look for a type definition, the compiler must be informed of which sets for search. The compiler will scan all the sets it knows to find the type definition. once the compiler finds the correct program, the assembly information and type information will be added to the metadata of the generated managed module. By default, the C # compiler will automatically go to mscorlib. DLL programs are centrally searched. mscorlib. dll contains all the core types defined in FCL. for example, the following example describes how to create a namespace compnyname {// companyName Class A {// companyName. A Class B {...} // CompanyName. A. B} namespace office // companyName. Office class c {...} // CompanyName. office. c} in C #, The namespace is implicitly public, and we cannot use any access modifier to modify it. finally, the relationship between namespaces and the Assembly is not necessarily related. In particular, multiple types belonging to the same namespace may be implemented in Multiple Programming sets. for example, system. io. the filestream type is in mscorlib. DLL assembly, while system. io. the filesystemwatcher type is implemented in system. DLL assembly, but in fact, there is no system at all. collections. in general, a DLL Assembly contains multiple namespaces. For example, the namespace above is generated as an NST assembly. How can this problem be solved? Project project. properties. General attributes. Here, the Assembly name (NST) and output type (select class library) are available. What should I do if I want to reference type C? See the following: Add NST in the reference of the project. DLL, however, using companyName. office; // the compiler will automatically find the Assembly and actually find the NST. the DLL assembly C-Py = new C (); // This is the c instance.