2017-09-07 1 views
9

ボックス化されたintの場合、 object boxedInt = 0がVisual Studioのイミディエイトウィンドウでis objectis 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ウィンドウとスクリーンショット:[ツール]の下で

+0

はい。たとえば、上記のコードの後に​​ブレークポイントを設定するとき。 –

+0

私はあなたが 'boxedInt == typeof(object);' –

+3

@SouvikGhosh 'boxedInt'を' Type'オブジェクトに入れなければならないと思います。 – Servy

答えて

1

> Option->デバッグオプションを有効にして、 "レガシーC#とVB式評価ツールを使用する"を再度デバッグしてください。

enter image description here

更新:

問題は、ここに報告されています:

https://developercommunity.visualstudio.com/content/problem/31283/and-operation-of-boolean-is-wrong.html

+0

本当にうまくいくので、これは役に立つ回答です。しかし、それは非レガシー(つまり、より良いと思われる)モードで観測された動作を望む理由とそれがバグかもしれないかどうかについては答えません。私はこれを投票しますが、正しい答えとしてそれを受け入れません。 –

+0

@Marco Eckstein、私はこの問題を報告し、他のメンバーと話し合います。最新の情報があれば、ここでそれを共有します。 –

+0

@Marco Eckstein、https://developercommunity.visualstudio.com/content/problem/31283/and-operation-of-boolean-is-wrong.htmlにも同様の問題が報告されています。製品チームのメンバーがフォローアップします、そこにあなたのコメントを共有することもできます。 –

関連する問題