Method name

From Wikipedia, the free encyclopedia

A method name in object-oriented programming is an identifier not only uniquely identifying a subroutine or event handler, but more importantly providing a hint to the programmer (or other programmers) about what the method can be expected to do.

[edit] In general

It's considered good practice to form a method name out of a verb, or a combination of noun and verb.

For example:

  • init() // meaning, "initialize"
  • CalculateTotal
  • shape.print()

[edit] For event handling

For example, an event handler called btnExit_Click would reasonably be expected to respond to a mouse click event on a form's exit button. The convention used in VB and C# is to combine the name of a control with the name of the event that acts on it, separated by an underscore character. Another example might be txtAmount_lostFocus used when the focus leaves an amount-entry textbox; the program could respond with a data validation routine.