473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Update current Item in LIST<T>

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

Thanks
Dec 28 '05 #1
4 27879
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]
- mv*@spam.guard.caspershouse.com

"Vivek" <vi****@xtra.co.nz> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
How do I update a current item in the LIST<T>?

Thanks

Dec 28 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: uq**************@TK2MSFTNGP10.phx.gbl...

| 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

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 28 '05 #3
I believe so. Sometimes, it's just so hard to remember...
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joanna Carter [TeamB]" <jo****@not.for.spam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: uq**************@TK2MSFTNGP10.phx.gbl...

| 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

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 28 '05 #4
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Vivek" <vi****@xtra.co.nz> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
How do I update a current item in the LIST<T>?

Thanks


Dec 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
5
by: Jimp | last post by:
Why can't I cast List<MyObject> to ICollection<IMyObject>. MyObject implements IMyObject, and of course, List implements ICollection. Thanks
4
by: bob_jeffcoat | last post by:
Hi, Have class B which subclasses from class A. I have a List<B> and I'm trying to get a List<A> without writing a stupid loop everytime I want to do it. So I tried this method: public...
3
by: janzon | last post by:
Hi! Sorry for the bad subject line... Here's what I mean. Suppose we deal with C++ standard integers lists (the type is indifferent). We have a function f, declared as list<intf(int); Now...
9
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus,...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: swiftalpha | last post by:
Aloha, Smallish problem: I know how to serialize objects and all, but this has me worried: Asume this class. Person is a nice simple object. public class PersonList : List<Person> {...
0
by: Weeble | last post by:
On Jun 20, 11:10 pm, Göran Andersson <gu...@guffa.comwrote: I did it that way because CopyTo has a whole bunch of failure cases to take care of (multi-dimensional array, not enough space,...
6
by: A.Rocha | last post by:
Hi, I need save to text file a List<type>, but i dont wont serialize. // List<mytypemyList = new List<mytype>(); anyone can help me? --
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.