This is a concept I cannot understand. I have a class
Class Employee
{
public int id;
public string name;
}
List<Employee> lst = new List<Employee>();
Employee o = new Employee();
o.id = 1;
o.name = "Darshan";
lst.Add(o);
Employee o1 = new Employee();
o1.id = 2;
o1.name = "Gopal";
lst.Add(o1);
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "name";
comboBox1.DataSource = lst;
The above doesn't work. But when I change the public fields with get and set, then it works.
Is there any way I can bind without get and set properties?
Public fields are also accessible outside class. You can read and write the value of that field anywhere. Then why can't we use them in Binding? Why to use properties?