R
Rafael Veronezi
Hello people,
It's clear to me that the great difference between fields and properties, is
that with properties you can write code to the routines that assign and
return the values, wich is in fact recorded in a private field (the common
scenario)...
My question is...
It's common to see people that constructs properties that could work
perfectly like a field... For example, I have two properties, name and
email:
(C#)
public class MyClass
{
private string _Name;
private string _Email;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public string Email
{
get { return _Email; }
set { _Name = value; }
}
}
Ok, it's well declared... I took long writing that code to explain well my
question, is, what is the advantage using properties in a case like this,
where the class would work exatcly the same declaring Name and Email
directly public fields?
Thanks,
Rafa
It's clear to me that the great difference between fields and properties, is
that with properties you can write code to the routines that assign and
return the values, wich is in fact recorded in a private field (the common
scenario)...
My question is...
It's common to see people that constructs properties that could work
perfectly like a field... For example, I have two properties, name and
email:
(C#)
public class MyClass
{
private string _Name;
private string _Email;
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public string Email
{
get { return _Email; }
set { _Name = value; }
}
}
Ok, it's well declared... I took long writing that code to explain well my
question, is, what is the advantage using properties in a case like this,
where the class would work exatcly the same declaring Name and Email
directly public fields?
Thanks,
Rafa