編譯器錯誤 CS0103
更新:2007 年 11 月
錯誤訊息
名稱 'identifier' 不存在於目前內容中
嘗試使用類別、命名空間或範圍中沒有的名稱。請檢查名稱的拼字,以及您的 using 陳述式和組件參考,以確定可使用您嘗試使用的名稱。
如果您在迴圈內或在 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);
}
}
}