Felix said:
Well, the OP wanted to index using an integer. I can't think of a
sensible way to do this with something that is NOT enumerable.
The type of the data used for the index isn't relevant. Not all integers
are mapped to enumerable data (*).
That's not even counting that we have no idea whether the actual use of an
indexer the OP has in mind is an integer. Sample code often has a way of
not being _precisely_ the way the code will be used in a real program
(never mind situations where the sample code isn't even valid, compilable
code
![Smile :) :)](/styles/default/custom/smilies/smile.gif)
).
Pete
(*) Example:
In the code below, there are likely a handful of values that any given int
could map to. Perhaps a few dozen, for potentially thousands of integers.
It's not helpful at all to be able to enumerate the mapped-to values in
terms of the mapping itself.
class HomeroomIndexer
{
private Dictionary<int, Homeroom> _dict;
public Homeroom this[int studentID]
{
get
{
Homeroom homeroom;
if (_dict.TryGetValue(studentID, out homeroom))
{
return homeroom;
}
return null;
}
}
}
class StudentRoster
{
private HomeroomIndexer _hi;
public HomeroomIndexer Homeroom
{
get { return _hi; }
}
}
class A
{
private StudentRoster _roster;
void DoSomething(int studentID)
{
Homeroom homeroom = _roster.Homeroom[studentID];
}
}