3、根据委托(delegate)的知识,请完成以下用户控件中代码片段的填写:(10) 
namespace test 

public delegate void OnDBOperate(); 
public class UserControlBase : System.Windows.Forms.UserControl 

public event OnDBOperate OnNew; 
privatevoidtoolBar_ButtonClick(objectsender,System.Windows.Forms.ToolBarButtonClickEventArgs e) 

if(e.Button.Equals(BtnNew)) 

//请在以下补齐代码用来调用OnDBOperate委托签名的OnNew事件。 




____________________________________________________________________ 
if( OnNew != null ) 
  OnNew( this, e ); 
答案是正确的吗?不是OnDBOperate(); 是这么定义的,所以答案我认为是
if( OnNew != null ) 
   OnNew(); 
请各位朋友解答。如果题目网上的答案是正确的,请告诉我为什么,谢谢,自当酬谢。

解决方案 »

  1.   

    if( OnNew != null )  
      OnNew(); 
    正确。if( OnNew != null )  
      OnNew( this, e ); 
    错误。public delegate void OnDBOperate();  
    说明这个委托不接受参数的。
      

  2.   

    如果不是你写错题目跟答案的话
    if(OnNew!=null)
    {
    OnNew();
    }   
      

  3.   

    http://www.cnblogs.com/xiaopeng84/archive/2007/03/28/690799.html
    第26题。
    用百度搜索asp.net面试题,第一个显示结果就是这个博客,看来很多人要倒霉了啊。