c#创建命名空间_在C ++中创建和使用命名空间

c#创建命名空间

Namespace is a container for identifiers. It puts the names of its members in a distinct space so that they don't conflict with the names in other namespaces or global namespace.

命名空间是标识符的容器。 它将其成员的名称放在一个不同的空间中,以便它们与其他名称空间或全局名称空间中的名称不冲突。

创建一个命名空间 (Creating a Namespace)

Creating a namespace is similar to creation of a class.

创建名称空间类似于创建类。

namespace MySpace
{
    // declarations
}

int main() 
{
    // main function
}

This will create a new namespace called MySpace, inside which we can put our member declarations.

这将创建一个名为MySpace的新命名空间,我们可以在其中放置成员声明。

创建命名空间的规则 (Rules to create Namespaces)

  1. The namespace definition must be done at global scope, or nested inside another namespace.

    名称空间定义必须在全局范围内完成,或嵌套在另一个名称空间内。

  2. Namespace definition doesn't terminates with a semicolon like in class definition.

    命名空间定义不以类定义中的分号结尾。

  3. You can use an alias name for your namespace name, for ease of use.

    您可以为名称空间名称使用别名,以方便使用。

    Example for Alias:

    别名示例:

    namespace StudyTonightDotCom
    {
        void study();
        class Learn 
        {  
            // class defintion
        };
    }
    
    // St is now alias for StudyTonightDotCom
    namespace St = StudyTonightDotCom;
  4. You cannot create instance of name

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值