Event handler or method overriding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sin Jeong-hun

    #1

    Event handler or method overriding

    When you create a new C# project, Visual Studio creates a main form
    for you. If you double click it, the Visual Studio automatically adds
    an event handler for the form's Load event. Then you can insert codes
    into that method. But, you can also override the form's OnLoad method
    and put that code there, which results in the same result.

    Since VS.NET does in the first way, it is the recommended way? Is
    there any performance differences in those two ways? Of course, like
    most cases, the form will not be inherited, or accessed by other forms.
  • Peter Duniho

    #2
    Re: Event handler or method overriding

    On Sun, 20 Jul 2008 19:00:02 -0700, Sin Jeong-hun <typingcat@gmai l.com>
    wrote:
    When you create a new C# project, Visual Studio creates a main form
    for you. If you double click it, the Visual Studio automatically adds
    an event handler for the form's Load event. Then you can insert codes
    into that method. But, you can also override the form's OnLoad method
    and put that code there, which results in the same result.
    >
    Since VS.NET does in the first way, it is the recommended way?
    No, not necessarily. It's just that the VS Designer adds events, not
    overrides.
    Is there any performance differences in those two ways?
    Negligible.

    The MSDN documentation always recommends overriding methods where
    possible, rather than subscribing to an event. Personally, that's what I
    tend to do. But as long as you don't specifically need the added control
    over execution that overriding gives you, I think it's just fine to use an
    event handler instead.

    Pete

    Comment

    Working...