How to convert an ArrayList to a strongly typed generic list without using a foreach?

前端 未结 4 1750
野趣味
野趣味 2020-12-04 15:05

See the code sample below. I need the ArrayList to be a generic List. I don\'t want to use foreach.

ArrayList arrayList = GetArra         


        
4条回答
  •  春和景丽
    2020-12-04 15:52

    Try the following

    var list = arrayList.Cast().ToList();
    

    This will only work though using the C# 3.5 compiler because it takes advantage of certain extension methods defined in the 3.5 framework.

提交回复
热议问题