System.Collections.Generic.List< string> & # 39;不包含'add&

本文关键字:包含 add System List Generic string Collections | 更新日期: 2023-09-27 18:02:06

我使用下面的代码

public HttpResponseMessage Getdetails([FromUri] string[] Column)
    {
      List<string> selectionStrings;
      var colDict = new Dictionary<string, string>()
            {
            {"CATEGORY", "STCD_PRIO_CATEGORY_DESCR.DESCR"},
            {"SESSION_NUMBER", "STRS_SESSION3.SESSION_NUM"},
            {"SESSION_START_DATE","Trunc(STRS_SESSION3.START_DATE)"}
            };
      foreach (string col in Column)
      {
        string selector = colDict[col];
        selectionStrings.add(string.Format("{0} AS {1}", selector, col));
      }
      var strQuery = string.Format(@"SELECT {0}
                                     from STCD_PRIO_CATEGORY");
  }

但是在

中得到错误
selectionStrings.add(string.Format("{0} AS {1}", selector, col));

System.Collections.Generic。列表'不包含add的定义和不接受first的扩展方法addSystem.Collections.Generic.List类型的参数可以是找到(您是否缺少using指令或程序集引用?)

我试着添加using System.Collections.Generic.List,但它不工作

System.Collections.Generic.List< string> & # 39;不包含'add&

尝试使用Add代替add

selectionStrings.Add(string.Format("{0} AS {1}", selector, col));

也初始化selectionStrings,目前你的代码会抛出一个异常

List<string> selectionStrings = new List<string>();

不要在任何初始化列表的地方看到

List<string> selectionStrings = new List<string>();

也是Add()而不是add。VS智能感知应该在这种情况下有所帮助。你用Notepad写代码吗?

添加shahaf所说的内容,您还需要实例化List

    List<string> selectionStrings = new List<string>();