OOPS - Interface, Abstract, Delegate well explained in code
using System;
using System.CodeDom.Compiler ;
namespace csharpoops
{
abstract class test1
{
public abstract int Fun(int a,int b);
public abstract int Fun(int a,int b);
public int
Checking(int d,int e)
{
d=3346;
e=123;
return d-e;
return d-e;
}
}
//Interface Example
//Interface Example
public interface Icalc
{
int
fn_add(int x, int y );
}
//Structure Example
struct employee
{
public string name;
public int age;
public long salary;
public int age;
public long salary;
}
//Enumerator Example
public enum state
{
off = 1,
on = 2
}
public delegate void simpledelegate();
public delegate int advdelegate();
delegate void CheckDelegate();
class
Class1:test1,Icalc
{
//Abstract Class
public override int Fun(int x,int y)
{
return x + y;
return x + y;
}
public int fn_add(int x, int y)
{
return x + y;
}
{
return y + z;
}
{
return x + y + z;
}
{
return x + y + z;
}
{
Console.WriteLine("Welcome to Delegates");
}
{
Console.WriteLine("Welcome to
after delegates");
}
string m_name;
string Value="";
public string name
{
get
{
return m_name;
}
set
{
m_name = Value;
}
}
{
int i1;
long
l1=3356544876;
Console.WriteLine("Logn value" + l1);
i1=(int)l1;
Console.WriteLine("Integer
value" + i1);
employee emp;
emp.name ="ravi";
emp.age
=25;
emp.salary = 10000;
Console.WriteLine("*****************structure
implementation*******************");
Console.WriteLine(emp.name);
Console.WriteLine(emp.age);
Console.WriteLine(emp.salary);
Console.WriteLine("*****************Enumerator
implementation*******************");
state x;
x = state.off;
{
case state.on:
Console.WriteLine("iam here at on state");
break;
case state.off:
Console.WriteLine("iam here at off state");
}
int y ;
y = 0;
switch(y)
{
case 1:
Console.WriteLine(state.off);
break;
case 2:
Console.WriteLine(state.on);
break;
}
Console.WriteLine("********************
Interface implementation ***********************");
Class1 obj = new Class1();
resint = obj.fn_add(3,4);
Console.WriteLine("the value of function add int " + resint);
long reslong;
reslong = obj.fn_add(2,1);
Console.WriteLine("the value of function add long " + reslong);
double resdbl;
resdbl = obj.fn_add(2,3,4);
Console.WriteLine("the value of function add double " + resdbl);
string resstring;
resstring = obj.fn_add("ravi","krishnan","rajasekaran");
Console.WriteLine("the value of function add string " + resstring);
Console.WriteLine("*********************** Delegate Implementation
***********************");
simpledelegate delobj = new simpledelegate(fn_welcome);
delobj();
simpledelegate delaftobj = new simpledelegate(obj.fn_afterdelg);
delaftobj();
Console.WriteLine("*********Abstract Class***********");
int result;
result = obj.Fun(4,69);
Console.WriteLine("The abstract class result is" + result);
Console.ReadLine();
Comments
Post a Comment