c# 中关键字
Prerequisite: Namespace in C#
先决条件: C#中的命名空间
If you want to include namespace in a program then we need to use using keyword. For example we use Console class which is defined in System namespace that’s why we need to include System namespace using using keyword.
如果要在程序中包含名称空间,则需要使用using关键字。 例如,我们使用在System名称空间中定义的Console类,这就是为什么我们需要使用using关键字包含System名称空间的原因。
If we want to use Console class without include then we can also access it with the help of . (dot) operator like that:
如果我们想使用不包含include的Console类,那么我们也可以借助来访问它。 像这样的(点)运算符:
System.Console.WriteLine("Hello World");
Example:
例:
using System;
using System.Collections;
using namespace1;
using namespace2;
namespace namespace1
{
class ABC
{
public void fun()
{
Console.WriteLine("Inside Namespace1");
}
}
}
namespace namespace2
{
class XYZ
{
public void fun()
{
Console.WriteLine("Inside Namespace2");
}
}
}
class Program
{
static void Main()
{
ABC OB1 = new ABC();
XYZ OB2 = new XYZ();
OB1.fun();
OB2.fun();
}
}
Output
输出量
Inside Namespace1
Inside Namespace2
Read more: Nested Namespace in C#
: C#中的嵌套命名空间
翻译自: https://www.includehelp.com/dot-net/using-keyword-in-c-sharp.aspx
c# 中关键字