Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 错误CS1729:类型'System.Collections.Generic.List<;字符串>';不包含接受'5';论据_C#_List_Constructor_Compiler Errors - Fatal编程技术网

C# 错误CS1729:类型'System.Collections.Generic.List<;字符串>';不包含接受'5';论据

C# 错误CS1729:类型'System.Collections.Generic.List<;字符串>';不包含接受'5';论据,c#,list,constructor,compiler-errors,C#,List,Constructor,Compiler Errors,我正在学习C和C,这个问题是给C的。这个问题是一本书中的代码,代码没有编译,错误是:error CS1729:typeSystem.Collections.Generic.List'不包含接受5'参数的构造函数 代码如下: public static void Main (string[] args) { List<string> names = new List<string>("Christa ",

我正在学习C和C,这个问题是给C的。这个问题是一本书中的代码,代码没有编译,错误是:error CS1729:type
System.Collections.Generic.List'不包含接受
5'参数的构造函数

代码如下:

    public static void Main (string[] args)
    {
        List<string> names = new List<string>("Christa ",
                                          "  Sarah",
                                          "Jonathan",
                                          "Sam",
                                          " Schmekowitz");
publicstaticvoidmain(字符串[]args)
{
列表名称=新列表(“Christa”,
“莎拉”,
“乔纳森”,
“山姆”,
“Schmekowitz”);
更改为
{
}

List name=新列表{“Christa”,
“莎拉”,
“乔纳森”,
“山姆”,
“Schmekowitz”};

正确
列表
初始化语法使用大括号:

List<string> names = new List<string> { "Christa ",
                                      "  Sarah",
                                      "Jonathan",
                                      "Sam",
                                      " Schmekowitz" };
List name=新列表{“Christa”,
“莎拉”,
“乔纳森”,
“山姆”,
“Schmekowitz”};
List<string> names = new List<string> { "Christa ",
                                      "  Sarah",
                                      "Jonathan",
                                      "Sam",
                                      " Schmekowitz" };