For accessing a variable outside the class we declare that variable as Public. Properties are used to access a private variable declared in a class to outside that class. Declaring a property as public using get and set, we can access that private variable from anywhere. So we can avoid the use of Public Variables.
Eg: Class Employee
{
private int employeeid
public int EmployeeId
{
get { return employeeid; }
set { employeeid= value; }
}
}
//from other forms create an object of class employee
Employee objEmp = new Employee();
int id = objEmp.EmployeeId;
A method is a code block containing a series of statements. Methods must be declared within a class or a structure. It is a good programming practice that methods do only one specific task. Methods bring modularity to programs
Shanky11, if this helps please login to Mark As Answer. | Alert Moderator