【问题标题】:Cannot convert method group 'EmIsNull' to non-delegate type 'bool'. Did you intend to invoke the method?无法将方法组“EmIsNull”转换为非委托类型“bool”。您是否打算调用该方法?
【发布时间】:2013-03-07 05:25:03
【问题描述】:
public static class MyExtention
{
    public static bool EmIsNull<T>(this T obj)
    {
        return (obj == null);
    }
}

//在主类中的用法

if(dataGridView1["IP", i].Value.EmIsNull)

//然后得到错误信息

错误 1:无法将方法组“EmIsNull”转换为非委托类型“bool”。您是否打算调用该方法?

有什么办法吗?

【问题讨论】:

    标签: c#


    【解决方案1】:

    您在末尾缺少函数括号 ()

    if(dataGridView1["IP", i].Value.EmIsNull())
    

    【讨论】:

      【解决方案2】:

      是的,它是一个方法,在if条件下你需要提到使用函数括号()。

      看下面的例子

      private bool Validation()
              { 
               foreach ( RadioButton rbtn in filetypepnl.Controls)
               {
               if(rbtn.Checked)
               {
                   return true;
               }
               }
               return false;
              }
      

      使用

      if(Validation())
       {
         if (ofd.ShowDialog() == DialogResult.OK){ }
       }
      

      【讨论】:

        猜你喜欢
        • 2013-02-18
        • 1970-01-01
        • 2013-10-23
        • 2017-06-23
        • 2012-03-27
        • 1970-01-01
        • 2015-12-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多