how to upcast object array to another type of object array in C#?

前端 未结 3 959
耶瑟儿~
耶瑟儿~ 2021-01-22 12:29

I want to upcast object array to different array of different object type like below

object[] objects; // assuming that it is non-empty

CLassA[] newObjects = obj

3条回答
  •  情歌与酒
    2021-01-22 13:22

    using System.Linq;
    
    newObjects = objects.Select(eachObject => (ClassA)eachObject).ToArray();
    

提交回复
热议问题