Results 1 to 2 of 2

Thread: Consequence of c# Interfaces

  1. #1
    PerezMorris is offline Senior Member
    Join Date
    Dec 2009
    Posts
    250
    Rep Power
    3

    Default Consequence of c# Interfaces

    I am learning c# language. I want to know what are Importance of c# Interfaces. Can anybody tell me Importance of c# Interfaces. Any help would be highly appreciated.

    Thanks in advanced.

  2. #2
    HallMiller is offline Senior Member
    Join Date
    Dec 2009
    Posts
    251
    Rep Power
    3

    Default

    In this example, the interface IPoint haves the property declaration, which is responsible for setting and getting the values. The class MyPoint haves the property execution.

    Code:
    // keyword_interface.cs
    // Interface implementation
    using System;
    interface IPoint 
    {
       // Property signatures:
       int a
       {
          get; 
          set; 
       }
    
       int b
       {
          get; 
          set; 
       }
    }
    
    class MyPoint : IPoint 
    {
       // Fields:
       private int myA;
       private int myB;
    
       // Constructor:
       public MyPoint(int a, int b) 
       {
          myA = a;
          myB = b;
       }
    
       // Property implementation:
       public int a 
       {
          get 
          {
             return myA;
          }
    
          set 
          {
             myA = value; 
          }
       }
    
       public int yb 
       {
          get 
          {
             return myB; 
          }
          set 
          {
             myB = value; 
          }
       }
    }
    
    class MainClass 
    {
       private static void PrintPoint(IPoint p) 
       {
          Console.WriteLine("a={0}, b={1}", p.a, p.b);
       }
    
       public static void Main() 
       {
          MyPoint p = new MyPoint(2,3);
          Console.Write("My Point: ");
          PrintPoint(p);
       }
    }

Similar Threads

  1. Abstract course or Interfaces in C#
    By TaylorRyan in forum Software Jargons
    Replies: 1
    Last Post: 04-20-2010, 01:34 PM
  2. Replies: 1
    Last Post: 01-23-2010, 03:00 PM
  3. Interfaces of Open Office's
    By laressa in forum Everything Else
    Replies: 0
    Last Post: 03-18-2009, 09:59 AM
  4. External Interfaces
    By ostin55 in forum Programming
    Replies: 0
    Last Post: 07-30-2008, 06:53 PM
  5. Interfaces
    By youckin in forum Wireless Networking
    Replies: 0
    Last Post: 06-20-2008, 09:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48