convert list to list

前端 未结 3 836
闹比i
闹比i 2021-01-04 05:05

How to convert List to List in C#?

相关标签:
3条回答
  • 2021-01-04 05:24

    Like this:

    List<long> longs = ints.ConvertAll(i => (long)i);
    

    This uses C# 3.0 lambda expressions; if you're using C# 2.0 in VS 2005, you'll need to write

    List<long> longs = ints.ConvertAll<int, long>(
        delegate(int i) { return (long)i; }
    );
    
    0 讨论(0)
  • 2021-01-04 05:42
    List<int> ints = new List<int>();
    List<long> longs = ints.Select(i => (long)i).ToList();
    
    0 讨论(0)
  • 2021-01-04 05:43
    var longs = ints.Cast<long>().ToList();
    
    0 讨论(0)
提交回复
热议问题