如何在C#中初始化字符串数组列表?

如何在C#中初始化字符串数组列表?,c#,arrays,list,C#,Arrays,List,我环顾四周,但找不到答案 我有以下代码: List<String[]> _myList = new List<String[]>(); List\u myList=newlist(); 我只想用值初始化它,但我不知道如何初始化。非常感谢试试这个: List<String[]> _myList = new List<String[]>{new String[]{"a","b"},new String[]{"c","d"}}; List{u my

我环顾四周,但找不到答案

我有以下代码:

List<String[]> _myList = new List<String[]>();
List\u myList=newlist();
我只想用值初始化它,但我不知道如何初始化。非常感谢

试试这个:

List<String[]> _myList = new List<String[]>{new String[]{"a","b"},new String[]{"c","d"}};
List{u myList=newlist{newstring[]{“a”,“b”},newstring[]{“c”,“d”};
这是列表初始值设定项的语法。

请尝试以下操作:

List<String[]> _myList = new List<String[]>{new String[]{"a","b"},new String[]{"c","d"}};
List{u myList=newlist{newstring[]{“a”,“b”},newstring[]{“c”,“d”};

这是列表初始值设定项的语法。

您可以尝试以下方法:

List<String[]> _myList = new List<String[]> { new String[] { "a", "b", "c", "d"}, 
                                              new String[] { "a", "b"},
                                              new String[] { "b", "c"} };
List<String[]> _myList = new List<String[]>()
        {
            new string[] { "string", "more string" },
            new string[] { "and more string"},
        };
_myList.Add(new string[] {"add more string"});
List\u myList=newlist{newstring[]{“a”、“b”、“c”、“d”},
新字符串[]{“a”,“b”},
新字符串[]{“b”,“c”};

这是集合初始值设定项语法。有关这方面的更多信息,请查看

您可以尝试以下方法:

List<String[]> _myList = new List<String[]> { new String[] { "a", "b", "c", "d"}, 
                                              new String[] { "a", "b"},
                                              new String[] { "b", "c"} };
List<String[]> _myList = new List<String[]>()
        {
            new string[] { "string", "more string" },
            new string[] { "and more string"},
        };
_myList.Add(new string[] {"add more string"});
List\u myList=newlist{newstring[]{“a”、“b”、“c”、“d”},
新字符串[]{“a”,“b”},
新字符串[]{“b”,“c”};

这是集合初始值设定项语法。有关这方面的更多信息,请查看

您可以这样做:

List<String[]> _myList = new List<String[]> { new String[] { "a", "b", "c", "d"}, 
                                              new String[] { "a", "b"},
                                              new String[] { "b", "c"} };
List<String[]> _myList = new List<String[]>()
        {
            new string[] { "string", "more string" },
            new string[] { "and more string"},
        };
_myList.Add(new string[] {"add more string"});

您可以这样做:

List<String[]> _myList = new List<String[]> { new String[] { "a", "b", "c", "d"}, 
                                              new String[] { "a", "b"},
                                              new String[] { "b", "c"} };
List<String[]> _myList = new List<String[]>()
        {
            new string[] { "string", "more string" },
            new string[] { "and more string"},
        };
_myList.Add(new string[] {"add more string"});
List{u myList=new List(){new string[1]{“Cool”},new string[2]{“allow”,“Cool”};
List\u myList=new List(){new string[1]{“Cool”},new string[2]{“allow”,“Cool”};

首先,列表不是一个数组,因为列表中可以有数量可变的项目;另一方面,数组有固定数量的项或成员,必须声明和遵守这些项或成员

using System.Collections.Generic;

Class Program



   {
        Static Void Main(string[] args)
        Var names = new List<string>
        {
             "Dave",
             "Steve",
             "Joe",
        };
   // you can get additional names added by using the Add keyword


       names.Add("Hillary")

     // If you want to print your list you can use the foreach loop 
       foreach(string name in names)
       Console.Writeline(names);
使用System.Collections.Generic;
班级计划
{
静态Void Main(字符串[]参数)
变量名称=新列表
{
“戴夫”,
“史蒂夫”,
“乔”,
};
//您可以使用Add关键字添加其他名称
姓名。加上(“希拉里”)
//如果要打印列表,可以使用foreach循环
foreach(名称中的字符串名称)
Console.Writeline(名称);

}

首先,列表不是一个数组,因为列表中可以有数量可变的项目;另一方面,数组有固定数量的项或成员,必须声明和遵守这些项或成员

using System.Collections.Generic;

Class Program



   {
        Static Void Main(string[] args)
        Var names = new List<string>
        {
             "Dave",
             "Steve",
             "Joe",
        };
   // you can get additional names added by using the Add keyword


       names.Add("Hillary")

     // If you want to print your list you can use the foreach loop 
       foreach(string name in names)
       Console.Writeline(names);
使用System.Collections.Generic;
班级计划
{
静态Void Main(字符串[]参数)
变量名称=新列表
{
“戴夫”,
“史蒂夫”,
“乔”,
};
//您可以使用Add关键字添加其他名称
姓名。加上(“希拉里”)
//如果要打印列表,可以使用foreach循环
foreach(名称中的字符串名称)
Console.Writeline(名称);
}