LINQ Bug?从long列表中获取字符串数组

Jal*_*aer 0 linq-to-objects

Unable to cast object of type 'System.Int64' to type 'System.String'. 从下面的代码片段中得到了这个 :

 IList<long> Ids = new List<long>();
 Ids.Add(6962056);
 Ids.Add(7117210);
 Ids.Add(13489241);

 var stringIds = Ids.Cast<string>().ToArray();
Run Code Online (Sandbox Code Playgroud)

和Booooooooooooom ....想法?

Chr*_*man 7

你不能长字符串转换为字符串.您需要指定要将long转换为字符串的操作.我更喜欢使用Linq来选择新值:

var stringIds = Ids.Select(id => id.ToString());
Run Code Online (Sandbox Code Playgroud)