Mar*_*ein 9 c# types visual-studio-debugging
对于盒装int,例如object boxedInt = 0在代码中定义,is object并在Visual Studio的立即窗口中is int返回false.这是一个bug,不是吗?
码:
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
Run Code Online (Sandbox Code Playgroud)
即时窗口:
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
Run Code Online (Sandbox Code Playgroud)
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
带Watch窗口的截图:
在“工具”->“选项”->“调试”下,请启用“使用旧版 C# 和 VB 表达式求值器”选项,然后再次调试。
更新:
该问题已报告如下: