简体   繁体   中英

Error CS1729: The type `System.Collections.Generic.List<string>' does not contain a constructor that takes `5' arguments

I'm learning C and C#, this question is for C#. This problem is code from a book, and the code doesn't compile, the error is:Error CS1729: The type System.Collections.Generic.List<string>' does not contain a constructor that takes 5' arguments.

Here is the code:

    public static void Main (string[] args)
    {
        List<string> names = new List<string>("Christa ",
                                          "  Sarah",
                                          "Jonathan",
                                          "Sam",
                                          " Schmekowitz");

Change the ( and ) to { and } .

Ie

List<string> names = new List<string>{"Christa ",
                                      "  Sarah",
                                      "Jonathan",
                                      "Sam",
                                      " Schmekowitz"};

Correct List initialization syntax uses braces:

List<string> names = new List<string> { "Christa ",
                                      "  Sarah",
                                      "Jonathan",
                                      "Sam",
                                      " Schmekowitz" };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM