开发者

Difference between 'using' and '#using' directive?

开发者 https://www.devze.com 2023-03-03 03:54 出处:网络
According to MSDN is: The using directive has two uses: 1)To allow the use of types in a namespace so that you do not have to

According to MSDN is:

The using directive has two uses:

1)To allow the use of types in a namespace so that you do not have to qualify the use of a type in that namespace:

 using System.Text;

2)To create an alias for a namespace or a type. This is called a using alias directive.

 using Project = PC.MyCompany.Project;

Edit1: When we say #using<mscorlib.dll> what does it do?

Is #using directive specific to C++/CLI ?

What is the basic difference between using and #us开发者_开发技巧ing?


The #using directive is C++. Basically it

Imports metadata into a program compiled with /clr.

It is is used to import Microsoft intermediate language (MSIL) file for its managed data and managed constructs.

mscorlib.dll is automatically referenced when compiling with /clr.

Source: http://msdn.microsoft.com/en-us/library/yab9swk4(v=VS.100).aspx

using on the other hand is applicable to both C++ and C# and you have defined its uses already. In C++:

using namespace System::Reflection;

Also:

#include <iostream>

int main() {
   std::cout << "Hello ";
   using namespace std;
   cout << "World." << endl;
}


#using is only used in C++ and includes another file to the one it's contained in.

using is specific to C# and allows you to use classes from the namespace it specifies.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号