更新:2007 年 11 月
错误消息
当前上下文中不存在名称“identifier”试图使用类、
如果在循环或者 try 或 if 块中声明一个变量,然后试图从封闭代码块或另一代码块访问此变量,会发生此错误。如下面的示例所示。
下面的示例生成 CS0103:
复制代码 | |
---|---|
// CS0103.cs using System; class MyClass { public static void Main() { // MyClass conn = null; try { MyClass conn = new MyClass(); // delete this line // and uncomment the following line and the line above the try // conn = new MyClass(); } catch(Exception e) { if (conn != null) // CS0103 Console.WriteLine("{0}", e); } } } |