我有一个带有此签名的方法:
IEnumerable<string> GetCombinations(string s, int length)
Run Code Online (Sandbox Code Playgroud)
我试图string.Join像这样使用它:
var combinations = GetCombinations(text, 2);
string result = string.Join(", ", combinations);
Run Code Online (Sandbox Code Playgroud)
但是我得到以下编译器错误:
cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'
不能string.Join拿一个IEnumerable<string>?
打电话.TaArray吗?
String.Join(", ",combinations.ToArray());
Run Code Online (Sandbox Code Playgroud)
编辑
另请参阅Dan J的答案:自.Net 4以来,String.Join的重载确实接受了IEnumerable.
| 归档时间: |
|
| 查看次数: |
1926 次 |
| 最近记录: |