c# - 运算符是否无法区分 short[] 和 ushort[]?
问题描述
考虑以下代码:
我用.NET framework 4.7.2
.
ushort[] a = new ushort[100];
if (a is short[])
{
Assert.Fail("This never happens.");
}
object b = a;
if (b is short[])
{
Assert.Fail("Why?");
}
第一个测试按预期工作(a
不是short[]
)。我的问题涉及第二个测试,出乎意料的是,它没有失败。
为什么会这样?
编辑:添加 MSIL(发布,优化)
.maxstack 8
IL_0000: ldc.i4.s 100
IL_0002: newarr [mscorlib]System.UInt16
IL_0007: isinst int16[]
IL_000c: brfalse.s IL_0018
IL_000e: ldstr "Why\?"
IL_0013: call void [(...).TestFramework](...).Assert::Fail(string)
IL_0018: ret
解决方案
推荐阅读
- ios - 如何在 Flutter App for iOS 中安装 Spotify SDK
- java - Java DatabaseMetaData getIndexInfo 参数近似值
- linguistics - 理解短语结构树模型
- ios - 如何在 Expo 39 上更新 iOS 版 Facebook SDK?
- php - 比较两个字符串而不考虑php中的空格或字符
- node.js - 使用 mongoose 更新 mongoDB 中的子文档
- mongodb - DioError [DioErrorType.response]:Http 状态错误 [400]
- python - 无法在 django 中导入 pycryptodome
- javascript - 简化 Javascript 代码的最有效方法
- wcf - 从 WCF 服务调用 Web API Core 时出现 401 错误