c# 命名空间命名规范_C#中的命名空间
c# 命名空间命名规范
C#命名空间 (C# Namespace )
In C# namespaces are used to group similar type of classes. Two classes with same name in different namespaces never conflict to each other.
在C#中,名称空间用于对相似类型的类进行分组。 在不同名称空间中具有相同名称的两个类永远不会相互冲突。
In C# namespace can be:
在C#中,命名空间可以是:
User defined
用户自定义
Pre defined, that is in-built in .NET class library
预定义,内置在.NET类库中
Here, we need to use using keyword to access defined namespaces.
在这里,我们需要使用using关键字来访问已定义的名称空间。
Syntax:
句法:
namespace <namespace_name> {//Write code here }Note:
注意:
To declare user defined namespace we need to use namespace keyword.
要声明用户定义的名称空间,我们需要使用namespace关键字。
If we want to access class defined inside namespace then we need use . (dot) Operator.
如果要访问命名空间中定义的类,则需要使用。 (点)运算符。
Example:
例:
using System; using System.Collections;namespace namespace1 {class ABC{public void fun(){Console.WriteLine("Inside Namespace1");}} }namespace namespace2 {class ABC{public void fun(){Console.WriteLine("Inside Namespace2");}} } class Program {static void Main(){namespace1.ABC OB1 = new namespace1.ABC();namespace2.ABC OB2 = new namespace2.ABC();OB1.fun();OB2.fun();} }Output
输出量
Inside Namespace1Inside Namespace2Read more: The 'using' Keyword in C#, Nested Namespace in C#
: C#中的“ using”关键字,C#中的嵌套命名空间
翻译自: https://www.includehelp.com/dot-net/namespaces-in-c-sharp.aspx
c# 命名空间命名规范
总结
以上是生活随笔为你收集整理的c# 命名空间命名规范_C#中的命名空间的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: HTH的完整形式是什么?
- 下一篇: c# 字节十六进制转十进制_用C中的十进