Convert List to object[]

前端 未结 8 1295
太阳男子
太阳男子 2020-12-13 19:35

I am looking for a one liner that transforms List into object[]. It\'s one liner, so I am not interested in solutions such as foreac

8条回答
  •  执笔经年
    2020-12-13 20:25

    In C# on .NET 2.0 (VS 2008) the following compiles and doesn't use LINQ (as far as I can see) for reference types.

     object[] oArray;
     List oList = new List();
     oArray = oList.ToArray();
    

    This does not require a cast as all reference types have object as their base.

提交回复
热议问题