Why can't I project ToString() in VB?
Posted
by
Martinho Fernandes
on Stack Overflow
See other posts from Stack Overflow
or by Martinho Fernandes
Published on 2011-01-10T12:18:05Z
Indexed on
2011/01/10
13:53 UTC
Read the original article
Hit count: 146
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?
© Stack Overflow or respective owner