答案 0 :(得分:2)
给定的接口定义了indexer operator ([]
)的覆盖。一个简单的使用示例:
class Point
{
public int X { get; set; }
public int Y { get; set; }
}
class PointCollection
{
public List<Point> collection { get; set; }
public Point this[int x, int y]
{
get => collection.FirstOrDefault(item => item.X == x && item.Y == y);
}
}
然后:
PointCollection points = new PointCollection();
var item = points[100, 200];