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.
code:
private string name;
public string Name
{
get
{return name;}
set
{name =value;}
}
..................
..................

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

Answers (10)

Unlimited Flat-Free License

SPONSORED BY

File APIs for .NET
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!