I want to define a class in C#. I found these two methods:
Method 1 :
public class customer
{
private string _name ;
private string _family;
public string Name
{
get { return __name; }
set { if(value=="")message(" نام کارخانه را وارد کنید ");
_name= value; }
}
public string Family
{
get { return _family; }
set { if(value=="")message(" نام کارخانه را وارد کنید ");
_family= value; }
}
public void AddCustomer()
{
add _name and _family to database
}
}
Method 2:
public class customer
{
public void AddCustomer(string name ,string family)
{
//code to add a customer
}
}
I am confused; which one should be used, and what the difference between these two methods? Which one is better and is more commonly used?