gpt4 book ai didi

c# - "is"运算符在立即窗口中对盒装值的工作方式不同

转载 作者:太空狗 更新时间:2023-10-29 17:58:54 25 4
gpt4 key购买 nike

对于盒装的 int,例如object boxedInt = 0 在你的代码中定义, is objectis int 在 Visual Studio 的 Immediate Window 中返回 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

微软 Visual Studio 企业版 2017
版本 15.3.3
VisualStudio.15.Release/15.3.3+26730.12

微软 .NET 框架
版本 4.7.02046

视觉 C# 2017 00369-60000-00001-AA135


带有 Watch 窗口的屏幕截图:

最佳答案

在 Tools->Option->Debugging 下,启用选项“Use the legacy C# and VB expression evaluators”,再次调试。

enter image description here

更新:

这里报告了这个问题:

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

关于c# - "is"运算符在立即窗口中对盒装值的工作方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46097476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com