I have a class, say DerivedBindingList<T>, which is derived from BindingList<T>.
I would like to use an indexer with the derived class, and have coded it as:
public T this[int index]
{
get
{
// Getter code
}
set
{
// Setter code
}
}
However, the compiler complains with the following message: “…hides inherited member ‘System.Collections.ObjectModel.Collection.this[int]’. Use the new keyword if hiding was intended.”
I can add the ‘new’ keyword and the compiler is happy, but should I be doing things differently in some way to avoid this warning?
Perhaps I have to use base.this[] somehow?
Thanks.
The indexer in
BindingListisn’t virtual, so you can’t override it – you’ll have to just hide it if you really want to do this.I don’t think I’d advise it though – member hiding is a recipe for confusing code. What are you trying to do? Do you definitely want to derive from
BindingList<T>instead of composing it (i.e. having a member of your class of typeBindingList<T>)? What is your new indexer going to do?