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

前端 未结 4 1767
野趣味
野趣味 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:43

    This is inefficient (it makes an intermediate array unnecessarily) but is concise and will work on .NET 2.0:

    List newList = new List(arrayList.ToArray(typeof(int)));
    

提交回复
热议问题