开发者

creating an event handler on object initialization

开发者 https://www.devze.com 2023-03-09 04:34 出处:网络
I have an object model like this: p开发者_如何转开发ublic class MyObject{ public int Prop1{get;set;}

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

精彩评论

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