ボックス化されたint
の場合、 object boxedInt = 0
がVisual Studioのイミディエイトウィンドウでis object
とis int
の両方を返します。false
がコードに定義されています。これはバグですね。"は"演算子はイミディエイトウィンドウでボックス化された値のために異なって動作します
コード:
int normalInt = 0;
Debug.WriteLine(normalInt.GetType().FullName); // System.Int32
Debug.WriteLine(normalInt is object); // true
Debug.WriteLine(normalInt is int); // true
Debug.WriteLine(normalInt is System.Int32); // true
object boxedInt = 0;
Debug.WriteLine(boxedInt.GetType().FullName); // System.Int32
Debug.WriteLine(boxedInt is object); // true
Debug.WriteLine(boxedInt is int); // true
Debug.WriteLine(boxedInt is System.Int32); // true
イミディエイトウィンドウ:
normalInt.GetType().FullName
"System.Int32"
normalInt is object
true
normalInt is int
true
normalInt is System.Int32
true
boxedInt.GetType().FullName
"System.Int32"
boxedInt is object
false // WTF?
boxedInt is int
false // WTF?
boxedInt is System.Int32
false // WTF?
object boxedInt2 = 0;
Expression has been evaluated and has no value
boxedInt2.GetType().FullName
"System.Int32"
boxedInt2 is object
true
boxedInt2 is int
true
boxedInt2 is System.Int32
true
のMicrosoft Visual Studioのエンタープライズ2017
バージョン15.3.3
VisualStudio.15.Release/15.3.3 + 26730.12
Microsoft .NET F ramework
バージョン4.7.02046
ビジュアルC#2017 00369-60000-00001-AA135
Watch
ウィンドウとスクリーンショット:[ツール]の下で
はい。たとえば、上記のコードの後にブレークポイントを設定するとき。 –
私はあなたが 'boxedInt == typeof(object);' –
@SouvikGhosh 'boxedInt'を' Type'オブジェクトに入れなければならないと思います。 – Servy