c# 中关键字_C#中的“使用”关键字

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# 中关键字

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值