Skip to main content

Posts

Showing posts from August, 2014

Interface demo

//using System; //Demo# 1 //class Demo //{ //    public static void Main() //    { //        Console.WriteLine("Hello Interfaces"); //        Console.ReadLine(); //    } //} //interface abc //{ //} ///* // Output //Hello Interfaces // */ //Demo# 2 //class Demo //{ //    public static void Main() //    { //        Console.WriteLine("Hello Interfaces"); //          Console.ReadLine(); //    } //} //interface abc //{ //    int x; //} ///* // Output //error CS0525: Interfaces cannot contain fields // */ //Demo# 3 //class Demo //{ //    public static void Main() //    { //        Console.WriteLine("Hello Interfaces"); //        Console.ReadLine(); //    } //} //interface abc //{ //    void xyz() // ...

Interfaces in C# (For Beginners)

Introduction Interfaces in C # provide a way to achieve runtime polymorphism. Using interfaces we can invoke functions from different classes through the same Interface reference, whereas using virtual functions we can invoke functions from different classes in the same inheritance hierarchy through the same reference. Before things start getting difficult let me start using simple and short examples to explain the concept of interfaces. Here's a short example that shows you what an interface looks like. P1.cs  Collapse  |  Copy Code class Demo { public static void Main() { System.Console.WriteLine( " Hello Interfaces" ); } } interface abc { } Output  Collapse  |  Copy Code Hello Interfaces The above program compiles and runs successfully to produce the desired output. The above program consists of a class  Demo  and within it an entry point function  Main()  that prints Hello Interfaces. The above progr...