"是"运算符在立即窗口中以不同的方式处理盒装值

时间:2017-09-07 13:19:14

标签: c# types visual-studio-debugging

对于盒装<select>,例如代码中定义了intobject boxedInt = 0is object都在Visual Studio的立即窗口中返回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

Microsoft Visual Studio Enterprise 2017
版本15.3.3
VisualStudio.15.Release / 15.3.3 + 26730.12

Microsoft .NET Framework
版本4.7.02046

Visual C#2017 00369-60000-00001-AA135

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 窗口的屏幕截图:

1 个答案:

答案 0 :(得分:1)

在工具 - &gt;选项 - &gt;调试下,请启用选项&#34;使用旧版C#和VB表达式评估程序&#34;,再次调试。

enter image description here

更新

这里已经报道了这个问题:

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