Académique Documents
Professionnel Documents
Culture Documents
namespace ConsoleApplication8
{
interface calc1
{
int add(int a, int b);
}
interface calc2
{
int sub(int x, int y);
}
interface calc3
{
int mul(int r, int s);
}
interface calc4
{
int div(int c, int d);
}
class Calculation : calc1, calc2, calc3, calc4
{
public int result1;
public int add(int a, int b)
{
return result1 = a + b;
}
public int result2;
public int sub(int x, int y)
{
return result2 = x - y;
}
namespace Inherit
{
class Mode
{
public void modesOf()
{
Console.WriteLine("There are Many Modes of Transport !!");
}
}
class vehicle : Mode
{
public void feature()
{
Console.WriteLine("They Mainly Help in Travelling !!");
}
}
class inheri : vehicle
{
public void Noise()
{
Console.WriteLine("All Vehicles Creates Noise !! ");
}
static void Main(string[] args)
{
inheri obj = new inheri();
obj.modesOf();
obj.feature();
obj.Noise();
Console.Read();
}
}
}
9) Program to implement the Hierarchical inheritance.
namespace Inherit
{
class Principal
{
public void Monitor()
{
Console.WriteLine("Monitor");
}
}
class Teacher : Principal
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
class Student : Principal
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
class Program
{
static void Main(string[] args)
{
Principal g = new Principal();
g.Monitor();
Teacher d = new Teacher();
d.Monitor();
d.Teach();
Student s = new Student();
s.Monitor();
s.Learn();
Console.ReadKey();
}
}
}
10) Program to implement event handling using delegates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public delegate void EventHandler();
class Program
{
public static event EventHandler _show;
static void Main()
{
// Add event handlers to Show event.
_show += new EventHandler(Dog);
_show += new EventHandler(Cat);
_show += new EventHandler(Mouse);
_show += new EventHandler(Mouse);
{
Console.WriteLine("Divide by Zero " +e.Message);
}
y = a / (b + c);
int[] d = { 5, 10 };
int f = 5;
try
{
int g;
g = d[2] / f - d[1];
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Array Index Error");
}
}
}
12) Program to implement user defined exceptions in C#