How to write Properties ( get, set ) in C#? and wher we can
How to write Properties ( get, set ) in C#? and wher we can write that one and what the use of that one?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Jul 24, 2013, 2:53 AM
http://www.c-sharpcorner.com/UploadFile/rajeshvs/PropertiesInCS11122005001040AM/PropertiesInCS.aspx
http://csharp-station.com/Tutorial/CSharp/Lesson10
Riyaz AkhtarPosted Jul 24, 2013, 2:45 AM
http://www.dotnetperls.com/property
Sunny SharmaPosted Jul 24, 2013, 2:11 AM
{get; set;} is a replacement for traditional Getter and Setter methods in C#;
You use it while defining properties of a class, like:
---------------------------------------
public class Car{
public Car();
public string Name {get; set;}
public string Type {get;set;}
}
---------------------------------------
You can see above we have two properties of Car and C# will create a private field for them automatically. You don't need to write any Getter and Setter code on your own.
Hope you got the point.
Happy Coding.
Cheers!