Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gtest-421.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ffa5a960c4091f0f6773cb63caa4fd573c00db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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");
	}
}