【问题标题】:Error CS1729: The type `System.Collections.Generic.List<string>' does not contain a constructor that takes `5' arguments错误 CS1729:类型“System.Collections.Generic.List<string>”不包含采用“5”参数的构造函数
【发布时间】:2013-11-28 23:44:59
【问题描述】:

我正在学习 C 和 C#,这个问题是针对 C# 的。这个问题是书上的代码,代码没有编译,错误是:Error CS1729: The type System.Collections.Generic.List&lt;string&gt;' does not contain a constructor that takes5' arguments。

代码如下:

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

【问题讨论】:

    标签: c# list constructor compiler-errors


    【解决方案1】:

    () 更改为{}

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

    【讨论】:

      【解决方案2】:

      正确的List 初始化语法使用大括号:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-16
        • 1970-01-01
        相关资源
        最近更新 更多