34

The only similar question to this I found was this and the answer suggested having to use Reflector to find out.

What about in just the majority of the cases? Generally, is the base method called first or last in a method?

I noticed in some libraries it is called at the beginning at the method and in the XNA Framework they're called at the end of methods (base.Update, base.Draw, et cetera).

Community
  • 1
  • 1
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136

2 Answers2

34

It depends on whether you want you derived behaviour to happen before or after the base behaviour.

And don't forget you can call the base method in the middle or not at all.

Having said that, in general it will be called as the first thing. Because then your overriding method has the option to 'overwrite' settings done by the base-class.

But in methods like Close or Dispose it is more customary (sometimes mandatory) to call it in the end.

H H
  • 263,252
  • 30
  • 330
  • 514
11

It entirely depends on what you want to do. There's not really a "general" rule about what should happen. For example, you might want to do some extra validation, then call the base method, then do something else. Or maybe you just want to time how long the base method takes to call.

Treat each case as an individual situation.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194