Place Ads here

Thursday, February 2, 2012

InterFace


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


interface ICalculate
{
    void IADD();
    void ISUB();
    
}


class Calculate : ICalculate /////////Child class Calculate Inherited Interface ICalculate
{
    #region ICalculate Members


    public void IADD()
    {
        //throw new System.NotImplementedException();


        int x, y, z;
        Console.WriteLine("Enter values for x and y");
        x = int.Parse(Console.ReadLine());
        y = Convert.ToInt32(Console.ReadLine());
        z = x + y;
        Console.WriteLine("Addition of x and y is: " + z);


    }


    public void ISUB()
    {
       // throw new System.NotImplementedException();


        int x, y, r;
        Console.WriteLine("Enter values for x and y");
        x = int.Parse(Console.ReadLine());
        y = Convert.ToInt32(Console.ReadLine());
       r = x - y;
        Console.WriteLine("Subtraction of x and y is: " +r);




    }


    
   #endregion
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interface
{
    class Program
    {
        static void Main(string[] args)
        {




            
            Console.WriteLine("An interface looks like a class, but has no implementation. The only thing it contains are declarations of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because they are inherited by classes and structs, which must provide an implementation for each interface member declared.");
            Console.WriteLine();

            Console.WriteLine("C# does not support multiple inheritence to overcome these problems we use interfaces. This is main use of Interfaces we have in C#.");
            Console.WriteLine();
            Console.WriteLine("Interfaces are a very logical way of grouping objects in terms of behavior. ");
            Console.WriteLine();
            ICalculate obj = new Calculate();/////Instance ie representative of Interface and Abstract class cannot be created
                                              /////ICalculate obj = new ICalculate();
                                              ////// object of interface is a representative of Class Calculate 
                                              ////// Break Point cannot be allocated for interface for debugging.
            obj.IADD();
            obj.ISUB();
            
            
            //Console.WriteLine("Division of 2 nos is");
            //Console.WriteLine("" + obj.IDIV(10,2));

        }
    }
}

No comments:

Post a Comment