Following example is a simple class creation where we use properties and fields. Fields are data holding values and like age or Name values. Properties are methods to user who creates them which would here return the age and set the age for a particular employee. Here Employee in this program is a type but (Employee Name-Ujjwal C# Tutor) is the instance or kind of an Employee type.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestingOops
{
class Employee
{
private int Age;
private string Name;
public int myAge()
{
return Age;
}
public void setAge(int someAge)
{
Age = someAge;
}
public string myName()
{
return Name;
}
public void setName(string someName)
{
Name = someName;
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee();
emp.setAge(42);
int ageresult=emp.myAge();
emp.setName("Ujjwal C# Tutor");
string nameresult=emp.myName();
Console.WriteLine("Employee Name is : \'{0}\' and Age is {1}", nameresult, ageresult);
Console.ReadKey();
}
}
}