G
Guest
The following code will not compile...
public bool active = false;
public void Activate(){}
public void Deactivate(){}
public void object_Activate(object sender, EventArgs e){
(active)? Deactivate() : Activate();
}
the compiler gives the following error...
"Only assignment, call, increment, decrement, and new object expressions can
be used as a statement"
Now the two statements here are both Calls? In which case this should
compile according to the given message?
If I change the code to this....
public bool active = false;
public bool Activate(){
return true;
}
public bool Deactivate(){
return false;
}
public void object_Activate(object sender, EventArgs e){
active = (active)? Deactivate() : Activate();
}
It compiles as I am now doing an assignment.
Is this an intentional feature of the C# compiler? And if so what is the
reasoning behind it? It doesn't matter hugely as it is easy enough to work
around.
Cheers
Rob
public bool active = false;
public void Activate(){}
public void Deactivate(){}
public void object_Activate(object sender, EventArgs e){
(active)? Deactivate() : Activate();
}
the compiler gives the following error...
"Only assignment, call, increment, decrement, and new object expressions can
be used as a statement"
Now the two statements here are both Calls? In which case this should
compile according to the given message?
If I change the code to this....
public bool active = false;
public bool Activate(){
return true;
}
public bool Deactivate(){
return false;
}
public void object_Activate(object sender, EventArgs e){
active = (active)? Deactivate() : Activate();
}
It compiles as I am now doing an assignment.
Is this an intentional feature of the C# compiler? And if so what is the
reasoning behind it? It doesn't matter hugely as it is easy enough to work
around.
Cheers
Rob