码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-10-04 12:22:50      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace Test10
 7 {
 8     class Program
 9     {
10         //int a = 0;            注意存放位置!!!!!
11         const int i = 927;
12         static void Main(string[] args)
13         {
14            int a = 0;
15             try
16             {
17                 //i = 112;
18                 a = i / a;
19                 Console.WriteLine(a);
20             }
21             catch (Exception e)
22             {
23                 Console.WriteLine(e.Message);
24                 Console.ReadLine();
25             }
26             finally
27             {
28                 System.Console.WriteLine("无论是否发生异常,我都会显示。");
29             }  
30         }
31     }
32 }

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

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

刚开始接触,可能感觉啥都新鲜,还请诸位知道,谢谢!

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

标签:

原文地址:http://www.cnblogs.com/liuyaozhi/p/4854387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!