相关疑难解决方法(0)

从IList <string>或IEnumerable <string>创建逗号分隔列表

从一个IList<string>或多个IEnumerable<string>?创建逗号分隔的字符串值列表的最简洁方法是什么?

String.Join(...)上的操作string[],从而可能是麻烦的与当类型,如工作IList<string>IEnumerable<string>不能容易地被转换成一个字符串数组.

c# string

806
推荐指数
12
解决办法
57万
查看次数

string.Join on List <int>或其他类型

我想将一个数组或整数列表转换为逗号分隔的字符串,如下所示:

string myFunction(List<int> a) {
    return string.Join(",", a);
}
Run Code Online (Sandbox Code Playgroud)

但是string.Join只List<string>作为第二个参数.做这个的最好方式是什么?

c# arrays string

76
推荐指数
3
解决办法
8万
查看次数

尝试串入IList

我正在尝试将第一个示例http://www.dotnetperls.com/convert-list-string实施到我的方法中,但是我很难匹配该方法的第二个参数:

string printitout = string.Join(",", test.ToArray<Location>);
Run Code Online (Sandbox Code Playgroud)

错误信息:

The best overloaded method match for 'string.Join(string,
System.Collections.Generic.IEnumerable<string>)' has some invalid arguments
Run Code Online (Sandbox Code Playgroud)

所有的IList接口也都使用IEnurmerable实现(除非有人希望我在这里未列出)。

class IList2
{
    static void Main(string[] args)
    {

     string sSite = "test";
     string sSite1 = "test";
     string sSite2 = "test";

     Locations test = new Locations();
     Location loc = new Location();
     test.Add(sSite)
     test.Add(sSite1)
     test.Add(sSite2)
     string printitout = string.Join(",", test.ToArray<Location>); //having issues calling what it needs.

     }
 }
string printitout = string.Join(",", test.ToArray<Location>);


public class Location
{
    public Location()
    { …
Run Code Online (Sandbox Code Playgroud)

linq interface c#-4.0

3
推荐指数
1
解决办法
4031
查看次数

标签 统计

c# ×2

string ×2

arrays ×1

c#-4.0 ×1

interface ×1

linq ×1