I now feel that to learn C# well is to know the basic syntax of C#, the new features of C#, and what C# can do!
Among them, I feel that NAMESPACE is very critical no matter what. It can be said that it is not just for C#, but the whole. NET is composed of NAMESPACE, so after reading the basic syntax of C#, I went straight to NAMESPACE and wrote down some of my feelings here, hoping to be helpful to those who will learn later.
NAMESPACE can be said to be omnipresent in programming in the new NET environment. In short, it gives me the feeling that the core of MS’s new generation language is NAMESPACE. We can do what we want and are willing to do through the existing NAMESPACE. Of course, if you feel that the existing ones are not enough for your use, you can also use the existing ones to expand and create your own NAMESPACE! (Why does it feel so much like the previous COM and DCOM?)
Now let’s talk about how to create a NAMESPACE!
To define a NAMESPACE, you first need to include keywords: namespace
The format is as follows:
namespace Your_nsname
{
//namespase main content;
}
Haha, it feels like it’s like Class or Struct is the same. However, apart from being similar in form, they are indeed different in many aspects. We will talk about the details later! Let’s look down first. . .
In the body of a NAMESPACE, you can reference other NAMESPACE! For example:
namespace Your_nsname{
//The following references System and System.xml with two NAMESPACE;
using System;
using System. One thing to note above is that if you want to reference NAMESPACE, you should reference it before declaring other types. The following is wrong:
namespace Your_nsname{
//Due to referencing System and System.Xml is placed after other statements, so. . .
using System;
using System.Xml;
}
There is another interesting thing about NAMESPACE, that is. . .
Let’s take a look at the following two methods first:
Method 1,
namespace N1.N2
{ class A {}
class B {}
Method 2,
namespace N1
{
namespace N2
Among the above methods of breeding, the second one is easy to understand, it is Create another NAMESPACE N2 in NAMESPACE N1, and there are two classes A and B in N2! What about the first one? In fact, the definitions of the above two methods are actually exactly the same. NAMESPACE can be defined nested. We can use the second method, which has a clearer sense of hierarchy. We can also use the first method. The difference is that in the first method, a separator must be used between N1 and N2. "." to indicate the hierarchical relationship between them!
Use the following method when using it:
N1.N2.A;
N1.N2.B;