C#: Array of references / pointers to a number of integers

前端 未结 6 1282
梦毁少年i
梦毁少年i 2020-12-19 23:19

I would like to hold references to a number of shorts in an array. I assumed I could just create the shorts and then add them to the array. So... every time the referenced o

6条回答
  •  粉色の甜心
    2020-12-19 23:54

    The fundamental problem is that short is a struct and not an object. So basically an array of short is actually an array of short and not an array of references to short objects.

    To solve the problem you can "box" the short in a class (but it's going to be tedious)

    Try with the following:

    public class MyShort { public Value { get; set; } }
    

提交回复
热议问题