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
While I can't offer details about the error, a simple workaround it:
From x In {1, 2, 3} Let str = x.ToString() Select str
For what it's worth, when you have the following line:
Dim b = From num In {1, 2, 3} Select num.ToString("d")
it is compiles and decompiles to (using Reflector, to C#):
public class Class1
{
[CompilerGenerated]
private static string _Lambda$__1(int num)
{
return num.ToString("d");
}
public void Test1()
{
IEnumerable b = new int[] { 1, 2, 3 }
.Select(new Func(Class1._Lambda$__1));
}
}
There doesn't seem to be any anonymous class along the way.