Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
AnswerRe: call private void btnSave_Click(object sender, EventArgs e) Pin
AspDotNetDev22-Mar-10 13:37
protectorAspDotNetDev22-Mar-10 13:37 
GeneralRe: call private void btnSave_Click(object sender, EventArgs e) Pin
Not Active22-Mar-10 14:09
mentorNot Active22-Mar-10 14:09 
QuestionForm is Flickering Pin
Jassim Rahma22-Mar-10 11:53
Jassim Rahma22-Mar-10 11:53 
AnswerRe: Form is Flickering Pin
Kristian Sixhøj22-Mar-10 12:00
Kristian Sixhøj22-Mar-10 12:00 
QuestionThe WebBrowser control Pin
BuggingMe22-Mar-10 10:24
BuggingMe22-Mar-10 10:24 
Questionrecording sound from speakers Pin
rosin722-Mar-10 9:14
rosin722-Mar-10 9:14 
AnswerRe: recording sound from speakers Pin
DaveyM6922-Mar-10 10:33
professionalDaveyM6922-Mar-10 10:33 
QuestionModify Collection using LINQ Pin
uusheikh22-Mar-10 9:05
uusheikh22-Mar-10 9:05 
I have a simple question, but i don't know how to do it.
I have a collection of data, and would like to query it using LINQ. Then, i want to modify the resultant collection, which updates the original collection

For example
i have the following collection
int[] data = { 0, 1, 2, 3, 4, 5 };

I want to select all data larger than 3 (thus 4 and 5), and then modify them by multiplying them with 10.
My final collection should look like this. (This is a simple example, in reality, i will be using a complex object)

data = {0, 1, 2, 3, 40 , 50};

I tried this; but doesn't update the original collection. Does ToList() return a copy of the collection?
How do i go about doing this?

int[] data = { 0, 1, 2, 3, 4, 5 };

            var a = from n in data
                    where n > 3
                    select n;



            List<int> b = a.ToList();
            for (int i = 0; i < b.Count(); i++)
            {
                b[i] = 10*b[i];
                Console.WriteLine(b[i]);
            }

            for (int i = 0; i < data.Count(); i++)
                Console.WriteLine(data[i]);


Data still contains 0,1,2,3,4,5 instead of 0,1,2,3,40,50,which is what i want.
Please help, many thanks.
AnswerRe: Modify Collection using LINQ Pin
Gideon Engelberth22-Mar-10 9:30
Gideon Engelberth22-Mar-10 9:30 
AnswerRe: Modify Collection using LINQ Pin
Dave Kreskowiak22-Mar-10 10:50
mveDave Kreskowiak22-Mar-10 10:50 
GeneralRe: Modify Collection using LINQ Pin
uusheikh22-Mar-10 16:03
uusheikh22-Mar-10 16:03 
QuestionHow can I receive mail? Pin
Member 621528422-Mar-10 9:02
Member 621528422-Mar-10 9:02 
AnswerRe: How can I receive mail? Pin
Richard MacCutchan22-Mar-10 9:39
mveRichard MacCutchan22-Mar-10 9:39 
AnswerRe: How can I receive mail? Pin
DaveyM6922-Mar-10 10:29
professionalDaveyM6922-Mar-10 10:29 
QuestionRandom Number Question Pin
rmeister2922-Mar-10 7:50
rmeister2922-Mar-10 7:50 
AnswerRe: Random Number Question Pin
harold aptroot22-Mar-10 7:59
harold aptroot22-Mar-10 7:59 
AnswerRe: Random Number Question Pin
Migounette22-Mar-10 8:32
Migounette22-Mar-10 8:32 
Questionuser Friendly Datagrid Pin
Amin shamooni22-Mar-10 7:11
Amin shamooni22-Mar-10 7:11 
AnswerRe: user Friendly Datagrid Pin
PIEBALDconsult22-Mar-10 8:37
mvePIEBALDconsult22-Mar-10 8:37 
Questionhow change buttons messagebox [modified] Pin
Amin shamooni22-Mar-10 7:06
Amin shamooni22-Mar-10 7:06 
AnswerRe: how change buttons messagebox Pin
dan!sh 22-Mar-10 7:08
professional dan!sh 22-Mar-10 7:08 
AnswerRe: how change buttons messagebox Pin
The Man from U.N.C.L.E.22-Mar-10 8:12
The Man from U.N.C.L.E.22-Mar-10 8:12 
AnswerRe: how change buttons messagebox Pin
Som Shekhar22-Mar-10 9:39
Som Shekhar22-Mar-10 9:39 
GeneralRe: how change buttons messagebox Pin
Amin shamooni24-Mar-10 6:33
Amin shamooni24-Mar-10 6:33 
GeneralRe: how change buttons messagebox Pin
Som Shekhar24-Mar-10 7:00
Som Shekhar24-Mar-10 7:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.