a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
29 lines
656 B
C#
29 lines
656 B
C#
using System;
|
|
|
|
public class OneOff
|
|
{
|
|
public static int Main ()
|
|
{
|
|
double[] darray = { 1.0, 2.0, 3.0 };
|
|
double[] clone = OneOff.Clone (darray);
|
|
Console.WriteLine (clone.Length);
|
|
return clone.Length == 3 ? 0 : 1;
|
|
}
|
|
|
|
private static T[] Clone<T> (T[] o)
|
|
{
|
|
if (o == null)
|
|
return null;
|
|
Type t = typeof (T);
|
|
if (t.IsValueType)
|
|
return (T[]) o.Clone ();
|
|
else if (t.IsArray && (t.GetElementType ().IsValueType || t.GetElementType () == typeof (string))) {
|
|
T[] copy = new T[o.Length];
|
|
for (int i = 0; i < o.Length; i++)
|
|
copy[i] = (T) (o[i] as Array).Clone ();
|
|
return copy;
|
|
} else
|
|
throw new ArgumentException ("oops");
|
|
}
|
|
}
|