編譯器警告 (層級 1) CS0183
更新:2007 年 11 月
錯誤訊息
指定的運算式永遠為提供的 ('type') 型別
如果條件陳述式永遠評估為 true,您就不需要條件陳述式。當您嘗試使用 is 運算子評估型別時,便會發生這個警告。如果評估為實值型別 (Value Type),則不需要檢查。
下列範例會產生 CS0183:
// CS0183.cs
// compile with: /W:1
using System;
public class Test
{
public static void F(Int32 i32, String str)
{
if (str is Object) // OK
Console.WriteLine( "str is an object" );
else
Console.WriteLine( "str is not an object" );
if (i32 is Object) // CS0183
Console.WriteLine( "i32 is an object" );
else
Console.WriteLine( "i32 is not an object" ); // never reached
}
public static void Main()
{
F(0, "CS0183");
F(120, null);
}
}