【问题标题】:must declare a body because it is not marked abstract, extern, or partial c#必须声明一个主体,因为它没有标记为抽象、外部或部分 c#
【发布时间】:2013-04-08 09:33:44
【问题描述】:

关于我为什么会收到此错误的任何想法?我知道这可能是一个简单的修复,但我对 C# 完全陌生,我找不到任何修复。

'SimpleMath.UI.Add_operation.btnCalculate_Click(object, System.EventArgs)' 必须声明一个主体,因为它没有标记为抽象、外部或部分

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System;


namespace SimpleMath.UI
{
    class Add_operation
    {
        public string Calculate(decimal i, decimal j)
        {
            return (i + j).ToString();
        }
        private void btnCalculate_Click(object sender, EventArgs e);

    }
}

谢谢。

【问题讨论】:

  • 嗯 - 你试过为btnCalculate_Click声明一个主体({})吗?
  • 您为什么不想为 btnCalculate_Click 声明一个主体?毕竟是一种方法(msdn.microsoft.com/en-us/library/ms173114(v=vs.80).aspx
  • 如果是有意的话,也许还可以解释一下你想用它没有身体来达到什么目的。

标签: c# declare


【解决方案1】:

您需要在btnCalculate_Click 方法中声明一个body

using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System;

namespace SimpleMath.UI
{
    class Add_operation
    {
        public string Calculate(decimal i, decimal j)
        {
            return (i + j).ToString();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
           // do some stuff here
           // or remove the method if it's empty
        }
    }
}

【讨论】:

    【解决方案2】:

    错误很清楚。您的方法 btnCalculate_Click 没有正文!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多