Can someone help me get my tiny brain around this? Given this struct:
struct Foo {
string _bar;
public string Bar {
get{return _bar;}
set{_bar = value;}
}
}
Why can I do this:
Foo foo = new Foo();
foo.Bar = "bar";
and this:
Foo[] foos = new Foo[1];
foos[0] = new Foo();
for(int i=0;i<foos.Length;i++) {
foos[i].Bar = "bar";
}
but *not* this:
Foo[] foos = new Foo[1];
foos[0] = new Foo();
foreach(Foo foo in foos) {
foo.Bar = "bar";
}
The compiler error is distinctly unhelpful: "The left-hand side of an
assignment must be a variable, property or indexer" - which it plainly is.
I understand why I can't modify the value of an intermediate expression
(CS1612), but what's the deal here? Am I getting my pass-by-value and
pass-by-ref's muddled?
cheers,
Jim
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.