I am new to C#. i was going through a tutorial. and it shows how to create accesor-mutator to a variable as shown below;
public String var1 {
get {return "";}
set {someVar = value;}
}
1.) Can't i create getters and setter like created in java
public getVar() {return "";}
public setVar(String x){var=x;}
2.) What is value
used in C# ?
You can, but that's much more annoying to use, and ignores C# coding guidelines.
value
is the implicit parameter to the setter. It contains the value that the caller is setting the property to. (the right side of the Property = something
call)
See the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With