views:

28

answers:

1

If I have a generic class like this:

public class Repository<T>
{
  public string Greeting(T t)
  {
    return "Hi, I'm " + t.ToString();
  }
}

which is extended like this:

public class FooRepository : Repository<Foo>

If FooRepository has a method called Greeting(Foo foo), does that method have the same signature as the base class method (i.e. hide or override it), or is it considered separate?

I'm a little confused to be honest.

+1  A: 

It hides the base method and the compiler will warn you about this. If you want to override it you need to mark it as virtual in the base class or use the new keyword in the derived class method to indicate to the compiler that you know what you are doing and the hiding is intentional.

Darin Dimitrov
Thanks for the clarification.
David