Here is definition of a class C:
class C {
// inner struct S
struct S {
public byte mb;
}
public void Foo() {
S s1;
S s2 = new S();
s1.mb = s2.mb = 20; // initialize s1, s2
// a List of S initialized with s1,s2
var ls = new List<S> { s1, s2 };
}
private int mi = 10; // A member of C
}
Suppose we create an instance of C and invoke C.Foo:
C c = new C();
c.Foo();
The data instances in above code namely - c.mi, s1, s2, ls[0], ls[1]
- are allocated on either stack or managed heap at run-time. The ls[0] and ls[1] here refer to the items in list ls at index 0 and 1 respectively. Note that as items in list ls are of value-type, writing ls[0] (or ls[1]) in C# code would result in creating a temporary immutable copy of original item; but that is not our intention here.
Select all those statements below that are entirely true about the memory location of above data instances: