Where is the living structure with the reference type as a property

I created a structure with a static array of reference type and properties that take an object from this array by a unique identifier stored in a struct, but I do not know what this makes sense, I want to save the structure on the stack.

struct TestStruct
{
 static TestClass[] Instances = new TestClass[16]; 
 int uid; //max value = 15
 TestClass Instance
 {
  get { return Instances[uid]; }
 } 
}
+3
source share
2 answers

Good, therefore Instances- a static variable, so it will be on the heap. Similarly, the array itself is a reference type, so it will be on the heap.

Only the variable uidis actually part of the value for a particular TestStruct and will be on the heap or on the stack depending on the context.

, ... ?

+2

.

TestClass - . , , . Instances .

+5

Source: https://habr.com/ru/post/1793886/


All Articles