Forums - C# Corner

Forum guidelines

Difference between a property and variable

Sep 29 2009 6:40 PM

Can anyone explain me difference between a property and variable. I found them more or less same like both are used for storing and retrieving values.

I saw a code where player info has to be strored and for that some properties were declared inside a class. Property names are Name, PlayerNo, Age.
private string name;
public string Name
{return name;}
{name =value;}

But we can easily do this task using variables.
So is there any advantage of using properties instead of variables.

Answers (10)

C# Corner Hyderabad Developer Conference


Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.