范围分辨率运营商::对成员访问操作符。在C#中 [英] Scope-resolution operator :: versus member-access operator . in C#

查看:195
本文介绍了范围分辨率运营商::对成员访问操作符。在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,有什么的区别 A ::乙 A·B ?我注意到的唯一区别是,只有可以用全球,但除此之外,有什么用区别?为什么他们都存在?

In C#, what's the difference between A::B and A.B? The only difference I've noticed is that only :: can be used with global, but other than that, what's the difference? Why do they both exist?

推荐答案

与::你可以做这样的事情...

with :: you can do things like...

 extern alias X;
 extern alias Y;
 class Test
 {
   X::N.A a;
   X::N.B b1;
   Y::N.B b2;
   Y::N.C c;
 }

和有些时候。是不明确的,以便::是必要的。这里是从C#语言规范

and there are times when . is ambiguous so :: is needed. here's the example from the C# language spec

namespace N
{
   public class A {}
   public class B {}
}
namespace N
{
   using A = System.IO;
   class X
   {
      A.Stream s1;         // Error, A is ambiguous
      A::Stream s2;        // Ok
   }
}

http://download.microsoft.com/download/0/B/ D / 0BDA894F-2CCD-4C2C-B5A7-4EB1171962E5 / CSHARP%20Language%20Specification.htm

这篇关于范围分辨率运营商::对成员访问操作符。在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆