错误“命名空间不能直接包含字段或方法等成员"是什么意思?意思? [英] What does error "A namespace cannot directly contain members such as fields or methods" mean?
问题描述
我将以下代码添加到我的 C# windows 窗体应用程序以在我单击关闭按钮时显示一个消息框.. 但它给了我以下错误..
I added following code to my C# windows form application to show a message box when i click the closing button.. But it gives me following error..
错误 CS0116 命名空间不能直接包含成员,例如字段或方法 ebay 源 C:\Users\Supun\Documents\Visual Studio2015\Projects\ebay source\ebay source\Form1.cs 107 Active
Error CS0116 A namespace cannot directly contain members such as fields or methods ebay source C:\Users\Supun\Documents\Visual Studio 2015\Projects\ebay source\ebay source\Form1.cs 107 Active
这是我使用的代码..
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dialog = dialog = MessageBox.Show(
"Do you really want to close the program?",
"SomeTitle",
MessageBoxButtons.YesNo);
if (dialog == DialogResult.No)
{
e.Cancel = true;
}
}
请问我需要做些什么来修复它?
What do I need to do to fix it please?
推荐答案
我想你已经在类之外声明了那个函数?
I would imagine you've declared that function outside of a class?
喜欢
namespace Something
{
private void Method()
{
}
}
代替
namespace Something
{
class MyClass
{
private void Method()
{
}
}
}
这篇关于错误“命名空间不能直接包含字段或方法等成员"是什么意思?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!