What is the Interface in C#

Now we are going to learn about the interface in c#
  • 3304

Introduction

In the C# language provide a special type of facilities polymorphism achieve at runtime way. A program made with the classes and class made with the method An interface make a program very easy and more compact. This is the function we can interfaces a different classes by the same interface reference.

Example

interface ABC{
int
x
get;
set; }
int y
{   get;
set
 }    }
class XYZ : ABC
    {
 private int myX;
 private int myY;
public XYZ(int x, int y){
myX = x;
myY = y;        }
public int x   {
get  {

return myX; }
set{
myX = value;
}}
public int y
 {
get {
return myY; }
set{
myY = value;}}}
class MainClass{
private
static void PrintPoint(ABC  A)  {
Console
.WriteLine("x={0}, y={1}", A.x, A.y);   }
public
static void Main()        {
XYZ
  A = new XYZ (2, 3);
Console.Write("XYZ: ");
  PrintPoint(A );
  Console.ReadLine();  }   }  }

Output

interface.jpg

© 2020 DotNetHeaven. All rights reserved.