在黄忠成的<深入剖析asp.net组件设计>的webtimer2组件中有一段代码?
[Category("Action")]
public event EventHandler Timer 
{
add
{
if(_timeControl == null)
_timeControl = new WebTimer();
_timeControl.Timer += value;
}
remove
{
if(_timeControl != null)
_timeControl.Timer -= value;
} } 其中,private WebTimer _timeControl = null; 
可我用的语言是vb.net,它不支持add/remove存取器,想问一下大家,用vb.net该如何编写代码以实现这个组件呢? 

解决方案 »

  1.   

    该如何用vb.net编写这段代码?
    我对C#不熟悉,所以对此段代码根本就不理解,还请大家帮忙
      

  2.   

    如果要模拟c#中这种机制,查 AddHandler。不过,VB中的事件机制不需要这么复杂。整个上面这一段,你定义一句话:
    <Category("Action")> public event Timer 
    万事大吉!
      

  3.   

    总的来说,c#要繁琐一些,但是功能要强一些。vb要容易一些,想的周到一些,但是有时候过于方面以至于写出了效率不是最好的代码你还没立刻发觉。
      

  4.   

    不对呀,
    单一句 public event timer
    不可能能实现,
    注意:
    有一句
    _timeControl = new WebTimer();
    这可是要实现的呀,
    如看过《深入剖析asp.net组件设计》的话,还请尝试编一下vb.net版的webtimer2组件试试看
      

  5.   

    this is one of those things that cannot be done easily in VB.NETlook, this guy wrote a book in VB.NET, but the example he gave here is in C#Defining Add and Remove Accessor Methods for Events in VB.NET
    http://www.informit.com/articles/article.asp?p=31535&rl=1if you insist to do it in VB.NET, consider to use delegates directly, seehttp://abstractvb.com/code.asp?A=1084
      

  6.   

    谢谢思归大哥,
    (不过我得还加点油修E文,虽早已了解思归大哥的风格,^_^)实际开发中我又碰到些问题,还请抽空给予解答:
    http://community.csdn.net/Expert/topic/4052/4052791.xml?temp=.3638117