Convert List to object[]

前端 未结 8 1318
太阳男子
太阳男子 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:33

    If you don't mind writing a very short, reusable function, the ConvertAll Extension Method might help:

    http://msdn.microsoft.com/en-us/library/73fe8cwf.aspx

    EDIT:

    This would work too

    List intList = new List() { 1, 3, 4 };
    object[] objectList = intList.ConvertAll(item => (object)item).ToArray();
    

提交回复
热议问题