【发布时间】:2010-11-13 19:39:30
【问题描述】:
调查一个错误,我发现这是由于 c# 中的这种怪异:
sbyte[] foo = new sbyte[10];
object bar = foo;
Console.WriteLine("{0} {1} {2} {3}",
foo is sbyte[], foo is byte[], bar is sbyte[], bar is byte[]);
输出是“True False True True”,而我预计“bar is byte[]”会返回 False。显然 bar 既是byte[] 又是sbyte[]?对于Int32[] 与UInt32[] 等其他有符号/无符号类型也会发生同样的情况,但对于Int32[] 与Int64[] 则不然。
谁能解释这种行为?这是在 .NET 3.5 中。
【问题讨论】:
标签: c# arrays types command-line-interface