Argentino Douglas <do*******************@yahoo.com.arwrote:
public struct I{
public int value;
}
private void ValuableHelper(List<I>i){
i=new List<I>();
for(int n=0;n<MAXVALUE;++n){
for(int m=0;m<MAXVALUE;++m){
PleaseHelpMe();
}
i[n].value=5; //Error is here
}
}
I am coding it as a window application,
Well, firstly, that's *not* a short but complete program. Please read
http://www.pobox.com/~skeet/csharp/incomplete.html
However, the cause of your problem is that you've got a struct - a
value type - and you're trying to change a value which is returned from
an indexer. You can't do that, and even if you did, it wouldn't do what
you wanted it to.
i[n] returns a value. If you modify that value, it won't change the
contents of the list at all.
Now, if I were a reference type, you'd be modifying the value *referred
to* by the reference in the list, and that would be a different matter.
This kind of problem is just one reason why mutable value types are
generally a bad idea.
Oh, and regards your other post: you can't expect replies *that*
quickly. You only left your original message for 9 minutes before
posting again!
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too