Why can't I project ToString() in VB?

前端 未结 3 1866
不知归路
不知归路 2020-12-11 00:25

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

3条回答
  •  伪装坚强ぢ
    2020-12-11 01:25

    I couldn't tell you exacly why VB has this ridiculousness, but the simple workaround is to put the method call in parens.

    Dim q = From x In {1, 2} Select (x.ToString())
    

提交回复
热议问题