I am using Linq to convert an array of any object to a CSV list:
String.Join(',', (From item In objectArray Select item.ToString()).ToArray())
This is giving me the strange error: ‘Range variable name cannot match the name of a member of the ‘Object’ class.’
I can get round it by wrapping the string in a VB StrConv method, with a setting of ‘Nothing’:
String.Join(',', (From item In oArray Select StrConv(item.ToString(), VbStrConv.None)).ToArray())
However, this seems like a bit of a hack and I would like to avoid it.
Does anyone have any ideas when this problems occurs, and any better ways to get round it?
Modify your code to:
The problem is VB gives a name to the variable returned by
Selectclause. Implicitly, it tries to give the nameToStringtoitem.ToString()which will clash withToStringmethod. To prevent so, you should explicitly specify a name (stringValin above line).