I am a VBA developer and new to C# Below is my Employee Class :
class Employee
{
public string name;
public Employee()
{
age = 0;
}
public void setName(string newName)
{
name = newName;
}
}
When I create an object of my Employeeclass, I can either use the method provided to set the value of name
Employee E1 = new Employee();
E1.setName("Name 1");
or I can set the name directly.
Employee E1 = new Employee();
E1.name = "Name 1"
The whole point is How can I stop users to set the value of my fields directly / without calling my method , If you could please tell me how can I set the values of my class fields efficiently.