Properties in interface

 
Interface can contain signatures of the following members:

    Methods
    Properties
    Indexers
    Events

Interface contains the property declaration and class have implementation of these property.

interface IPoint
    {
        // Property signatures:
        int x
        {
            get;
            set;
        }
 
        int y
        {
            get;
            set;
        }
    }
 
    class Point : IPoint
    {
        // Fields:
        private int _x;
        private int _y;
 
        // Constructor:
        public Point(int x, int y)
        {
            _x = x;
            _y = y;
        }
 
        // Property implementation:
        public int x
        {
            get
            {
                return _x;
            }
 
            set
            {
                _x = value;
            }
        }
 
        public int y
        {
            get
            {
                return _y;
            }
            set
            {
                _y = value;
            }
        }
    }
 
    class MainClass
    {
        static void PrintPoint(IPoint p)
        {
            Console.WriteLine("x={0}, y={1}", p.x, p.y);
            Console.ReadKey();
        }
 
        static void Main()
        {
            Point p = new Point(2, 3);
            Console.Write("My Point: ");
            PrintPoint(p);
        }
    }

Author: Pavan

I am asp.net developer have good knowledge of Asp.net ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API ASP.net with sql server. Hobbies - Blogging ,Games, Movies ,Teaching,Keeping myself update with new technologies