LINQ不能从转换'System.Collections.Generic.IEnumerable<串GT;'为“字符串[]' [英] Linq cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'

查看:326
本文介绍了LINQ不能从转换'System.Collections.Generic.IEnumerable<串GT;'为“字符串[]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,此代码

string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")));



我得到误差

i got error

不能从转换'System.Collections.Generic.IEnumerable<串GT;'到'字符串[]'

和怎么了出口逗号分隔的txt文本框?

And how can it export to comma seperated txt box ?

推荐答案

您可以只是转换一个IEnumerable到字符串数组通过调用的 ToArray的()扩展方法:

You can just convert an IEnumerable to an array of strings by calling the ToArray() extension method:

string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")).ToArray());



旁注:

Sidenote:

由于.NET 4.0 ,有的string.join 的的超载接受一个的IEnumerable<弦乐> ,使得调用的ToArray 过时

Since .NET 4.0, there's an overload of String.Join that accepts an IEnumerable<String>, making the call to ToArray obsolete.

这篇关于LINQ不能从转换'System.Collections.Generic.IEnumerable&LT;串GT;'为“字符串[]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆