C#: Is there a way to resize an array of unknown type using reflection?

后端 未结 5 1827
臣服心动
臣服心动 2021-01-25 02:06

My users pass me an array of some type, say int[] or string[]. I can easily query the types of the elements via GetElementType, and I can find out how long the array was when i

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-25 02:59

    Why not just create a new array of whichever type you need that is the size that you want? Then populate it from the array you want to resize, setting non existent values to some default.

提交回复
热议问题