Я не понимаю, почему d is long[]
и d is ulong[]
дают true
. Любые намеки на то, почему это работает? И второй вопрос, почему не работает приведение к double[]
?
using System;
public class Program
{
public static void Main()
{
long[] a = new Int64[10];
ulong[] b = (ulong[]) (Array) a;
Array d;
// not allowed
// double[] c = (double[]) (Array) a;
a[0] = -5;
// check types of a
d = a;
Console.WriteLine("d.GetType() {0}", d.GetType());
Console.WriteLine("a.GetType() {0}", a.GetType());
if(d is ulong[])
Console.WriteLine("{0}","d is ulong[]");
if(d is long[])
Console.WriteLine("{0}","d is long[]");
if(a is ulong[])
Console.WriteLine("{0}","a is ulong[]");
if(a is long[])
Console.WriteLine("{0}","a is long[]");
// check types of b
d = b;
Console.WriteLine("d.GetType() {0}", d.GetType());
Console.WriteLine("b.GetType() {0}", b.GetType());
if(d is long[])
Console.WriteLine("{0}", "d is long[]");
if(d is ulong[])
Console.WriteLine("{0}", "d is ulong[]");
if(b is long[])
Console.WriteLine("{0}", "b is long[]");
if(b is ulong[])
Console.WriteLine("{0}", "b is ulong[]");
Console.WriteLine("{0} {1}", a[0], b[0]);
}
}
Вывод:
d.GetType() System.Int64[]
a.GetType() System.Int64[]
d is ulong[]
d is long[]
a is long[]
d.GetType() System.Int64[]
b.GetType() System.Int64[]
d is long[]
d is ulong[]
b is ulong[]
-5 18446744073709551611