If you try to compile the query below in Visual Basic .NET, it fails.
From x In {1, 2} Select x.ToString()
The error given by the compiler is:
Range variable name cannot match the name of a member of the 'Object' class.
There is nothing wrong with the equivalent C# query, though:
from x in new[]{1, 2} select x.ToString()
This does not happen with the ToString
overload that takes a format (it is a member of Int32, not Object). It does happen with other members of Object, as long as they don't take an argument: with GetType and GetHashCode it fails; with Equals(object) it compiles.
Why is this restriction in place, and what alternatives can I use?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…