请问函数怎么返回 list<string>类型的值

解决方案 »

  1.   

    List<string> Some()
    {
      List<string> ls = new List<string>();
      return ls;
    }
      

  2.   

    如果是自己定义的类型 ,如
    list<model> 其中model是自己定义的类型,怎么还回
      

  3.   

    List<model> Some()
    {
      List<model> ls = new List<model>();
      return ls;
    }
      

  4.   

    需要using model所在命名空间
      

  5.   

    List<T> Some<T>(T t)
    {
      List<T> ls = new List<T>();
      ls.Add(t);
      return ls;
    }static void Main()
    {
      model m = new model();
      Some<model>(m);
      Some(m);  // 这样也可以,系统可以根据参数自动推断T的类型。
    }
      

  6.   

    List<T> Some<T>(params T[] ts)
    {
      List<T> ls = new List<T>(ts.Length);
      foreach (T t in ts)
      {
        ls.Add(t);
      }
      return ls;
    }static void Main()
    {
      model m = new model();
      Some<model>(m);
      model n = new model();
      Some(m, n);  // 这样也可以,系统可以根据参数自动推断T的类型。
    }
      

  7.   

    Some<string>("12", "345");
    Some(22, 334, 567);
    Some<int>(22, 334, 567);  // 与上行等价。
      

  8.   

    自定义的类型和系统定义的类型都是一样的用,全部按照class来处理