Dear C# experts,
Is there any way to parametrize generics with value type reference.
I want to do something like this :
myObject.ID = 1;
List myInts = new List();
myInts.add(ref myObject.ID);
myInts[0] = 2;
Assert.IsTrue(myObject.ID == 2);
Use value-type references with generic
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

AlanRank #669 · 3.6K reputationPosted Sep 15, 2008, 1:36 AM EDT
Not really.
The nearest you can get (assuming MyObject is a reference type) is:
myObject.ID = 1; myInts = new List();
List
myInts.Add(myObject);
myInts[0].ID = 2;
Assert.IsTrue(myObject.ID == 2); //true
clement5 reputationPosted Sep 15, 2008, 3:19 PM EDT
It's a shame we don't get the same flexibility as in C with pointers (list of int*).
I find it especially annoying for immutable types like string in c# : it means we can't modify
string references through a list.