Difference between Select and ConvertAll in C#

前端 未结 4 1122
遇见更好的自我
遇见更好的自我 2020-12-01 04:50

I have some List:

List list = new List { 1, 2, 3, 4, 5 };

I want to apply some transformation to elements of my list.

4条回答
  •  北海茫月
    2020-12-01 05:33

    Select is a LINQ extension method and works on all IEnumerable objects whereas ConvertAll is implemented only by List. The ConvertAll method exists since .NET 2.0 whereas LINQ was introduced with 3.5.

    You should favor Select over ConvertAll as it works for any kind of list, but they do the same basically.

提交回复
热议问题