Update current Item in LIST<T>

  • Thread starter Thread starter Vivek
  • Start date Start date
Viviek,

If T is a value type, then you have to store the value type to a temp
variable and then set it back when you are done making changes to it. If it
is a reference type, you can use the indexer and just access the item
directly from that.

Hope this helps.
 
"Nicholas Paldino [.NET/C# MVP]" <[email protected]> a écrit
dans le message de news: (e-mail address removed)...

| Viviek,
|
| If T is a value type, then you have to store the value type to a temp
| variable and then set it back when you are done making changes to it. If
it
| is a reference type, you can use the indexer and just access the item
| directly from that.

Am I suffering from déjà vu or haven't several people already answered this
poster's question in several different threads ?

Joanna
 
Do this :

// value type sample
//
List<int> li = new List<int>();
li.Add(12345);
li[0] = 54321; // It works

// reference type sample
//
List<object> lo = new List<object>();
lo.Add(null);
lo[0] = new List<int>();

Nicholas Paldino said:
Viviek,

If T is a value type, then you have to store the value type to a temp
variable and then set it back when you are done making changes to it. If it
is a reference type, you can use the indexer and just access the item
directly from that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vivek said:
How do I update a current item in the LIST<T>?

Thanks
 
Back
Top