Generics and Indexers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

trying to create a generic indexer where the class definition does not have a
<T>
psedo code below.



public myClass{
public T this<T>[ValueType item]{
get{
return null;
}
}
}



other than creating two methods for get and set are there any other
solutions? or explinations as to why this would not work


Any help would be very much appriciated
 
Not without creating some kind of (invented) Indexer<T> class to act as
an intermediary; this would add code to the caller (e.g.
obj.GetIndexer<float>()[123]=39F) such that it is probably easier to
just to forget about an indexer, e.g. obj.SetValue(123,39F) or
SetValue<float>(123,39F) [depending on whether T-inference applies -
i.e. GetValue would always need the T, SetValue probably not as it can
infer from the param)...

Marc
 
Back
Top