Suppose I declare a generic List containing values of a struct type:
struct MyStruct { public MyStruct(int val1, decimal val2) : this() { Val1 = val1; Val2 = val2; } public int Val1 {get; private set;} public decimal Val2 {get; private set;} } List<MyStruct> list;
Does the List<> store each individual value as a boxed struct, allocated individually on the heap? Or is it smarter than that?
There is no boxing.
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/359cf58a-f53d-478e-bc31-1507e77c9454/
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx