C SHARPE

PART-A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

5.Demonstrate arrays of interface types in C#.NET array

 
  
 
 
 
 

/*5.Demonstrate arrays of interface types in C#.NET*/

 using System;
namespace AbstractClassMethods
{
    class Program
    {
        static void Main()
        {
            ImplementationClass1 obj1 = new ImplementationClass1();
            //Using obj1 we can only call Add method
            obj1.Add(10, 20);
            //We cannot call Sun method
            //obj1.Sub(100, 20);

            ImplementationClass2 obj2 = new ImplementationClass2();
            //Using obj2 we can call both Add and Sub method
            obj2.Add(10, 20);
            obj2.Sub(100, 20);

            Console.ReadKey();
        }
    }
    
    interface ITestInterface1
    {
        void Add(int num1, int num2);
    }
    interface ITestInterface2 : ITestInterface1
    {
        void Sub(int num1, int num2);
    }

    public class ImplementationClass1 : ITestInterface1
    {
        //Implement only the Add method
        public void Add(int num1, int num2)
        {
			
			int result=num1+num2;
            Console.WriteLine("Sum of {0} and {1} is  ={2}",num1,num2,result);
        }
    }

    public class ImplementationClass2 : ITestInterface2
    {
        //Implement Both Add and Sub method
        public void Add(int num1, int num2)
        {
			 int result=num1+num2;
            Console.WriteLine("Sum of {0} and {1} is {2} ",num1,num2,result);
        }
			
        public void Sub(int num1, int num2)
        {
			int result=num1-num2;
            Console.WriteLine("subtraction of {0} and {1} is  {2}",num1,num2,result);
        }
    }
}