編譯器警告 (層級 1) CS0420
更新:2007 年 11 月
錯誤訊息
'identifier': volatile 欄位的參考將不會視為 volatile
volatile 欄位通常不應使用 ref 或 out 參數傳遞,因為在函式範圍內不會將它視為 volatile。不過這種情形有例外狀況,例如呼叫連鎖的 API 時。和其他警告一樣,在您有意使用 volatile 欄位做為參考參數的少數情況中出現任何警告時,可以使用 #pragma warning 停用這個警告。
下列範例會產生 CS0420:
// CS0420.cs
// compile with: /W:1
using System;
class TestClass
{
private volatile int i;
public void TestVolatile(ref int ii)
{
}
public static void Main()
{
TestClass x = new TestClass();
x.TestVolatile(ref x.i); // CS0420
}
}