共用方式為


編譯器警告 (層級 2) CS0252

更新:2007 年 11 月

錯誤訊息

可能誤用了參考比較; 若您是要做數值比較,請將左邊轉換為型別 'type'

編譯器正在進行參考比較。如果您要比較字串值,請將運算式的左邊轉換為 type。

下列範例會產生 CS0252:

// CS0252.cs
// compile with: /W:2
using System;

class MyClass
{
   public static void Main()
   {
      string s = "11";
      object o = s + s;

      bool b = o == s;   // CS0252
      // try the following line instead
      // bool b = (string)o == s;
   }
}