how interface works in c# code example
Example 1: c# interface property
interface InterfaceExample
{
int Number { get; set; }
}
class Example : InterfaceExample
{
int num = 0;
public int Number { get { return num; } set { num = value; } }
}
Example 2: c# interface properties
public interface ISampleInterface
{
string Name
{
get;
set;
}
}
Example 3: creating interface in C#
using System;
namespace Grepper_Docs
{
public interface IWhatever
{
bool doSomething();
}
class Program : IWhatever
{
static void Main(string[] args)
{
var pro = new Program();
pro.doSomething();
}
public bool doSomething()
{
return true;
}
}
}