c# - Why left-hand side of an assignment must be a variable property or indexer? -


private arraylist arr = new arraylist();  private arraylist test() {     return arr; } private void whymustvariable() {     test() = new arraylist();   // error: left-hand side of assignment must variable property or indexer } 

why cannot test() = ...; thanks.

when writing test().xyz = xxx first execute test onbiously returns instance of arraylist (btw. should consider use list<t> instead nowadays, typed , safes casting every element in list actual type). can of course want instance, e.g. call method or set of properties. equivalent doing this:

var val = test(); val.mymember = 3; 

however when using test() = ... you´re assigning new value return-value of method, makes no sense.

i suppose want instead provide parameter method. method should expect one:

arraylist test(int myint) {     // myint } 

and call this:

var list = test(3); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -