.net - How to make a readonly C# List by non declaring its set attribute -


i have list<string> mylist in class want readonly class users.

list<strign> mylist {get;}  private void setlistvalue() {     mylist = new list<string>();     mylist.add("ss"); } 

like thought set mylist value inside class in private members , make readonly class users. realised declaring way i'm unable set value.

try:

public list<string> mylist {get; private set;} 

this let set inside class, not outside. note not stop external clients updating list, reference it.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -