I have this code in base class
protected virtual bool HasAnyStuff<TObject>(TObject obj) where TObject:class
{
return false;
}
In child class I am overriding
protected override bool HasAnyStuff<Customer>(Customer obj)
{
//some stuff
if Customer.sth etc
return false;
}
I am getting this error
”’Type parameter declaration must be an identifier not a type”’
What is it I am doing wrong here?
You can’t override a generic method’s type parameter in a derived class. To achieve a similar functionality, one option is to have your base class be a generic class, and have your derived class such as
where
BaseClassis declared asAlternatively, depending on exactly how your derived class is being used, you can just override the
HasAnyStuffmethod with a non-genericCustomerargument.However, note that the new
HasAnyStuffwill not be called if you are not working with an instance ofDerivedClass. That is to say,will call
BaseClass‘s generic method, notDerivedClass‘s non-generic method.