blob: 8f2ac9d56c921e977496eaaab7a511d362ba2e5b (
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
29
30
31
32
33
34
35
36
37
38
|
using System;
public class Test {
public static Comparison<U> WrapComparison<U>(Comparison<U> comparison)
{
return delegate(U x, U y) { return comparison(x, y); };
}
public delegate int MyComparison<V> (V x, V y);
public static MyComparison<W> WrapMyComparison<W>(MyComparison<W> myComparison)
{
return delegate(W x, W y) { return myComparison(x, y); };
}
}
public class Foo {
static int compare (int x, int y)
{ return x - y; }
static int compare (string x, string y)
{ return string.Compare (x, y); }
static void test (int i)
{
if (i != 0)
throw new Exception (""+i);
}
public static void Main ()
{
Comparison<int> ci = Test.WrapComparison<int> (compare);
Comparison<string> cs = Test.WrapComparison<string> (compare);
Test.MyComparison<int> mci = Test.WrapMyComparison<int> (compare);
Test.MyComparison<string> mcs = Test.WrapMyComparison<string> (compare);
test (ci (1,1));
test (cs ("h", "h"));
test (mci (2,2));
test (mcs ("g", "g"));
}
}
|