Formally, this is the indexed property. This is how:
class PlayerSet {
internal Player this[int index, int jerseyNumber] {
get {
return FindPlayer(index, jerseyNumber);
}
}
}
However, it's questionable if the whole idea makes sense. Usually, you can find one single item by index, or zero items, and one single item by key, or zero items. The key and index may contradict. Perhaps you should better use two different property, any this was the reason of many questions, because many people failed to figure out the syntax. One of the problems is identical types of the index and the key. This is one of the ways:
class JerseyNumber {
internal JerseyNumber(int index) { this.Index = index; }
internal int Index { get; private set; }
}
interface IKeyedPlayerSet {
Player this[JerseyNumber jerseyNumber] { get; }
}
class PlayerSet : IKeyedPlayerSet {
public Player this[JerseyNumber jerseyNumber] {
return FindPlayerByKey(jerseyNumber.Index);
}
internal Player this[int index] { }
}
These are just the ideas. I don't know some important detail of your implementation of player collection, so something in my samples may be not adequate to it, but I hope you still can figure out what to do.
—SA