참고 :
string myClass = "my-Class";
은 위의 완벽 괜찮습니다.
당신 말 :
compiler should give warning.
그것을해야합니까? 실제로 모호함이 없습니다.또한 유형의 이름으로 변수의 이름을 정말 드문
public class MyRandom
{
public Random Random { get; private set; }
public MyRandom()
{
// Is this ambiguous? No--the left HAS to be the property;
// the right HAS to be the type name.
Random = new Random();
}
}
이 아니에요 :
이 꽤 일반적인 시나리오를 생각해 보자. 일부 멤버가 겹치는 경우에만 모호성이 있습니다. 예 :
public class MyThreadPool
{
public static void Add(Thread thread)
{
Console.WriteLine("Called the static method.");
}
}
public class SomeOtherClass
{
public List<Thread> MyThreadPool { get; private set; }
public SomeOtherClass()
{
MyThreadPool = new List<Thread>();
}
public void DoSomethingAmbiguous()
{
// To me, it would make sense for the compiler to issue a warning here,
// as it seems rather ambiguous (to me at least). However, it doesn't,
// which tells me the behavior is defined somewhere in the spec (I'm too lazy
// to check).
MyThreadPool.Add(null);
}
}
내 눈! 하지만 +1, 지금은 내가 궁금 해서요 ... – Cameron
컴파일러가 경고를주는 이유는 무엇입니까? 완전히 다른 두 가지 상황에서 myClass를 사용하고 있으며 컴파일러에 대한 모호성이 없습니다. –
차이점은 컨텍스트입니다. 구문 분석기는 토큰이 객체인지 클래스인지 여부에 따라 컨텍스트를 기반으로 결정할 수 있습니다. –