关于C# 泛型接口的代码?
本文介绍了关于C# 泛型接口的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
看c# 高级编程,书中的例子 有一段看不明白。
public Rectangle this[int index] {。。。}
全部代码:
//
public interface IIndex<out T>
{
T this[int index] { get; }
int Count { get; }
}
public class RectangleCollection : IIndex<Rectangle>
{
private Rectangle[] data = new Rectangle[3]
{
// ……
};
public static RectangleCollection GetRectangles()
{
return new RectangleCollection();
}
**public Rectangle this[int index]**
{
get
{
if (index < 0 || index > data.Length)
throw new ArgumentOutOfRangeException("index");
return data[index];
}
}
public int Count
{
get
{
return data.Length;
}
}
}
解决方案
看不明白就再去看看 泛型 跟 索引器
这篇关于关于C# 泛型接口的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文