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# 中關鍵字