开发者

creating an event handler on object initialization

I have an object model like this:

p开发者_如何转开发ublic class MyObject{

  public int Prop1{get;set;}
  public int Prop2{get;set;}

  public void MyObjectInit()
  {
    this.Prop1 = 0;
    this.Prop2 = 0;
  }

}

How do I create an event handler for MyObject that triggers when the object is initialized and runs MyObjectInit.

Thanks


Why use an event handler. Just use the object constructor.

public void MyObject()
{
   MyObjectInit();
}

Or better yet, move the code of MyObjectInit into the constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜