In C #, why can't I pass an unassigned object variable in a parameter outand then assign it?
If I try to do this, a compiler error occurs: "A local variable <xyz>cannot be declared in this scope, because it will have a different value for <xyz>..."
eg.
void MyMethod(int x, out MyObject mo) { **MyObject** mo = new MyObject(); }
MyObject mo;
MyMethod(1, out mo);
EDIT: Now I see my mistake. I changed the above code to what I had. MyObjectin stars should not be.
source
share