using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
delegate void Delegate();
interface I<T>
{
event Delegate DE;
T this[int i]
{
get;
set;
}
List<T> age
{
get;
set;
}
void Say();
}
class c : I<c>
{
public event Delegate DE;
public c this[int i]
{
get { return age[i]; }
set { DE(); Say(); age[i] = value; }
}
public List<c> age
{
get;
set;
}
public void Say()
{
Console.WriteLine("123");
}
}
class b : I<c>
{
public event Delegate DE;
public c this[int i]
{
get { return age[i]; }
set { DE();Say(); age[i] = value; }
}
public List<c> age
{
get;
set;
}
public void Say()
{
Console.WriteLine("456");
}
}
class Program
{
static void Main(string[] args)
{
I<c> Ic = new c();
I<c> lb = new b();
Ic.DE += deC;
lb.DE += deB;
lb = Ic;
lb.age = new List<c>();
lb.age.Add(new c());
lb[0] = new c();
Console.WriteLine("S");
Console.ReadKey();
}
static void deC()
{
Console.WriteLine("c");
}
static void deB()
{
Console.WriteLine("B");
}
}
}
接口中定义事件,索引器,属性,方法
最新推荐文章于 2024-08-24 02:00:00 发布