コンパイラの警告 (レベル 1) CS0183

更新 : 2007 年 11 月

エラー メッセージ

式は常に指定された型 ('type') です。

条件付きステートメントが常に true になる場合、条件付きステートメントは不要です。この警告は、型の評価に is 演算子を使用した場合に発生します。評価の対象が値型の場合、条件判定は不要です。

次の例では警告 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); 
   }
}