Home > Net >  C # namespace and scope of some question
C # namespace and scope of some question

Time:09-20

 using System; 
using System.Collections.Generic;
Using System. The Text;

The namespace ConsoleApp1
{
Class A
{

}

The namespace Controllers
{
The class Con
{

}

The namespace Api
{
The class Test
{
ApiB. Test1 Test1=new ApiB. Test1 ();//here why can access to the ApiB space???????
}
}

The namespace ApiB
{
The class Test1
{
Models. Mo Mo=new Models. Mo (); Why can access to the Models of space//here???????
}
}
}

The namespace Models
{
The class Mo
{

}

The namespace Entity
{
The class Song
{

}
}
}
}


My understanding of the namespace is similar to the concept of computer file directory, the above Test class in ConsoleApp1. Controllers. In the Api, why can access to the ApiB (ConsoleApp1. Controllers. ApiB)?

Another is by the same token, the Test1 class in ConsoleApp1. Controllers. The ApiB, why can access to Models (ConsoleApp1. Models) the contents of the

If I can understand is to write a fully qualified, similar to the absolute path; But the above this kind of not fully qualified to write a bit like a relative path to write, but don't like the feeling of relative paths, reasoning, guidance, thank you

CodePudding user response:

Models. Mo, bring namespace can
Or using Models;
So Mo directly, omit Models, can also

CodePudding user response:

refer to the second floor of guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
Models. Mo, bring namespace can
Or using Models;
So Mo directly, omit Models, can also


I know, I mean I understand some of the fully qualified, the good understanding;
You said using Models; Can't be so using
Test1 class in ConsoleApp1. Controllers.
in the ApiBModels (ConsoleApp1 Models)

Don't understand this is how a relative relationship can access to

CodePudding user response:

In c #, a namespace can be mutual access,
When there is the same cs class library file, can be directly through the namespace name name direct access to the class in the space,

If in the other classes to access, use absolute paths to access, such as: you wrote ConsoleApp1. Controllers. ApiB
Also can be achieved,

CodePudding user response:

In c #, namespaces can visit each other, you can use the using namespace name, you can also use absolute paths access,
When there is the same cs class library file, can be directly through the namespace name name direct access to the class in the space,

CodePudding user response:

reference 4 floor morliz son hin reply:
in c #, namespaces can visit each other,
When there is the same cs class library file, can be directly through the namespace name name direct access to the class in the space,

If in the other classes to access, use absolute paths to access, such as: you wrote ConsoleApp1. Controllers. ApiB
Also can realize,


Not yo, in different cs class library file, also can visit each other, the actual testing and has nothing to do in not in the same class files, completely follow the namespace structure
  •  Tags:  
  • C#
  • Related