这是什么意思?这是、什么意思

2023-09-04 00:21:18 作者:朕可是太高冷

没错正如标题所说,我觉得我一直在寻找在C#code,当我看到这一段时间回来,我从来没有把它在意,但到底是什么 :: 意味着C#。我觉得我看到的东西像 myVar的::的Process.Start()

Exactly as the title says, I think I was looking at c# code when I saw this a while back, I never took much notice of it, but what does :: Mean in c#. I think I saw something like myVar::Process.Start()

推荐答案

这是命名空间别名限定符 - 如果你使用的命名空间的别名:

It is the namespace alias qualifier - if you use namespace aliases:

using config = System.Configuration;

...

var value = config::ConfigurationManager.AppSettings["Somthing"];

这有助于当你有类型与在同一范围内的同名歧义。

It helps disambiguating when you have types with the same name in the same scope.

例如 - 如果你有几个类(一个用于家具,一个旅程的腿),无一不是在导入的命名空间,其结果是当您使用在code编译器无法分辨出哪一个你的意思,那么如果你有一个命名空间别名命名空间,你可以使用<别名> ::腿引用你的意思是确切类型

For example - if you have several Leg classes (one for furniture, one for the leg of a journey), and both are in imported namespaces, with the result that when you use Leg in your code the compiler can't tell which one you mean, then if you have a namespace aliases to the namespaces, you can use <alias>::Leg to refer to the exact type you mean.

有一个默认的别名 全球全球命名空间。

There is a default alias global for the global namespace.