Working with Properties in C#

Rajesh_Kumar
Posted by Rajesh_Kumar under C# category on | Points: 40 | Views : 620

public class Project_Master
{
public Project_Master()
{
}

#region PRIVATE FIELDS
private int _project_id;
private string _project_name;
private int _emp_id;
private decimal _budget;
#endregion

#region PUBLIC PROPERTIES
public int Project_ID
{
get { return _project_id; }
set { _project_id = value; }
}

public int Employee_ID
{
get { return _emp_id; }
set { _emp_id = value; }
}

public string Project_Name
{
get { return _project_name; }
set { _project_name = value; }
}
#endregion
}
//Now setting or assigning properties in any class
Project_Master prj = new Project_Master();

prj.Project_ID = 1;
prj.Employee_ID = 20;
prj.Project_Name = "ABC";

//Now getting or accessing properties in same class
int project_id = prj.Project_ID;
int employee_id = prj.Employee_ID;
string project_name = prj.Project_Name;

Comments or Responses

Login to post response