Usage of instance,class and reference variables in C#.Net
The following example demonstrate the usage of instance , class
and reference variables.
using System;
class Dept
{
int deptno;
public void
setDeptNo(int dno) {deptno=dno;}
}
class Employees
{
int empno; //Instance variable
static int total_emp; //Class variable
Dept dept; //Reference variable
public void
setInfo(int eno,int dno) //Instance
function
{
empno=eno;
dept=new
Dept();
dept.setDeptNo(dno);
total_emp++;
}
public static int
getTotal() //Class Function
{ return total_emp; }
}
public class Class1
{
public static void Main (string [] args)
{
Employees
e1=new Employees();
e1.setInfo(101
,10);
Employees
e2=new Employees();
e2.setInfo(102,
20);
Console.WriteLine(Employees.getTotal());
Console.Read();
}
}
No comments:
Post a Comment