Click here to Skip to main content
15,885,133 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a List. List is a type class (MyClass). MyClass have same attribute (e.g. Name and Description - both type of string).
I fill List (Name and Description). Later I want update only Description. This Description I have in List (type of string).
It is possible update List without FOREACH (without need fill both attributes)?
Both List have same size (aaaa and NewDecsr).

C#
class MyClass
{
    public string Name { get; set; }
    public string Descr { get; set; }
}

C#
List<myclass> aaaa = new List<myclass>();
....

C#
List<string> NewDescr = new List<string>();
....

Something like this?
C#
aaaa[].Descr = NewDesc;


Thank you
Posted
Updated 2-Jul-13 20:33pm
v2
Comments
StM0n 3-Jul-13 2:59am    
Which framework-version?
smoula99 4-Jul-13 0:18am    
.NET 3,5

Is something like this?
C#
for (int i = 0; i< aaaa.Count; i++)
{
    aaaa[i].Descr = NewDescr[i].Descr;
}
 
Share this answer
 
Comments
StM0n 3-Jul-13 2:59am    
Plain and simple :) have a five
smoula99 3-Jul-13 3:56am    
yes, thanks
but I need use for (or foreach)

maybe I will have 50000 item of list
then will it slowly?
thanh_bkhn 3-Jul-13 4:06am    
I think 50,000 item will not be a problem.
smoula99 3-Jul-13 4:20am    
ok, thank you (i thought for solution will be using LINQ)
i use solution with for loop
Just fiddling around, so no need to vote
C#
var toSkip = 0;

aaaa.ForEach(simpleClass => {
    simpleClass.Title = NewDescr.Skip(toSkip++).First();
});

just curios, could it be achieved otherwise :)
 
Share this answer
 
Comments
smoula99 4-Jul-13 8:15am    
yes, it is what I want to find

thank you
smoula99 9-Jul-13 3:25am    
How Can I transfer List (type of string) - created and filled to List (type of class - where I want fill only 1 part of class, type of string) without using cycle FOR

ZItems.ForEach(x => new Item().ItemName = x) here I would like use ToList(), but it not possible
ZItems.ForEach(x => List2.Add(new Item().ItemName = x)) this indicate error
StM0n 10-Jul-13 1:33am    
ZItems.ForEach(title => { List2.Add(new MyClass() { Title = title }); });
smoula99 10-Jul-13 2:09am    
you are best man for create this effective part of code
can you give me link where I can read (learn) about effective using this programing
thanks you
StM0n 10-Jul-13 2:42am    
good start for lambdas -> http://www.codeproject.com/Articles/507985/Way-to-Lambda

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900