We all know what is interface in c#.
And all of we know some property of interface like it not contain any field
only property etc etc.
Now one question came in my mind few
years back when I was learning interface in C#. One question came in my mind ok
interface cannot contain data member, shall it contain property? Still I can
remember immediately I tried this in my laptop .And the result is.
Yes interface may contain property.
Just like function. And we have to implement that property to our implemented
class. Below example is to show that.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
namespace BlogProject
{
interface Person
{
string Name { get; set; }
}
class PersonImplement : Person
{
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
PersonImplement p = new PersonImplement();
p.Name = "Sourav";
Console.WriteLine(p.Name);
Console.ReadLine();
}
}
}
No comments:
Post a Comment