您的位置:首页 > 其它

错误 10 非静态的字段、方法或属性“Test10.Program.a”要求对象引用

2015-10-04 11:48 519 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test10
{
class Program
{
//int a = 0;            注意存放位置!!!!!
const int i = 927;
static void Main(string[] args)
{
int a = 0;
try
{
//i = 112;
a = i / a;
Console.WriteLine(a);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
finally
{
System.Console.WriteLine("无论是否发生异常,我都会显示。");
}
}
}
}


在第10行那里因为自己开始定义了a,导致“非静态的字段、方法或属性“Test10.Program.a”要求对象引用”错误出现,将变量声明放到 Main方法里自然就好了。

另外,catch (Exception e),最后的e可以用任何ex等表示,只要ex.Message保持对应即可。

刚开始接触,可能感觉啥都新鲜,还请诸位知道,谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: