错误消息:无法从'System.Collections.Generic.IEnumerable'转换为'string []' [英] Error message: cannot convert from 'System.Collections.Generic.IEnumerable' to 'string[]'

查看:1726
本文介绍了错误消息:无法从'System.Collections.Generic.IEnumerable'转换为'string []'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下C#源代码:(asp.net版本:3.5)

  // map来自'string'类型
map = string.Join(,TrackMap.Split('|')。Select(x => string.Format(< a href = \{0} \class = \lightview \>< img src = \{0} \style = \margin-right:30px; \width = \120 \height = \ 80 \/> gh< / a>,x)));

问题是,我收到以下错误消息:


参数'2':无法从
'System.Collections.Generic.IEnumerable'转换为'string []'


和错误消息:

lockquote

最好的重载方法匹配'string.Join(string ,string [])'
有一些无效参数


我的问题是我该如何解决它? (也许在web.config文件中添加一些代码?添加'using'-someting?)

解决方案

.NET 3.5尚未支持加入< T>(String,IEnumerable< T>),但支持 Join(String,Object []) / code>,因此,您只需调用 ToArray 方法即可将 IEnumerable 转换为 Array

  map = string.Join(,TrackMap.Split ';')。Select(x => string.Format(...,x))
.ToArray());


I have the following C# source: (asp.net version:3.5)

 //map is from 'string' type
 map = string.Join("", TrackMap.Split('|').Select(x => string.Format("<a href=\"{0}\" class=\"lightview\"><img src=\"{0}\" style=\"margin-right:30px;\" width=\"120\" height=\"80\"/>gh</a>", x)));

The problem is that I get this error message:

Argument '2': cannot convert from 'System.Collections.Generic.IEnumerable' to 'string[]'

And the error message:

The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments

My qustion is how can I fix it? (maybe add some code in the web.config file? add 'using'-someting?)

解决方案

Since you are in .NET 3.5 which has not yet supported Join<T>(String, IEnumerable<T>), but supports Join(String, Object[]), so, you just need to call ToArray method in order to convert IEnumerable to Array:

map = string.Join("", TrackMap.Split('|').Select(x => string.Format("...", x))
                                         .ToArray());

这篇关于错误消息:无法从'System.Collections.Generic.IEnumerable'转换为'string []'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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