Linq无法从'System.Collections.Generic.IEnumerable <string>'转换为'string []'

use*_*839 3 c# linq

我有这个代码的问题

string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")));
Run Code Online (Sandbox Code Playgroud)

我收到了错误

cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'

它如何导出到逗号分隔的txt框?

slo*_*oth 10

您可以通过调用ToArray()扩展方法将IEnumerable转换为字符串数组:

string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")).ToArray());
Run Code Online (Sandbox Code Playgroud)

边注:

由于.NET 4.0,有一个超负荷String.Join接受的IEnumerable<String>,使得调用ToArray过时.