0

我有以下 C# 源代码:(asp.net 版本: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)));

问题是我收到此错误消息:

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

和错误信息:

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

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

4

2 回答 2

6

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());
于 2013-04-18T15:29:50.017 回答
2

string.Join with the overload that takes an IEnumerable<String> was new in .NET 4, so you cannot use it in 3.5.

So this should work:

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)
            .ToArray()));
于 2013-04-18T15:30:47.093 回答