/
generic-delegate.2.cs
67 lines (52 loc) · 1.3 KB
/
generic-delegate.2.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
public class ClassA {}
public delegate int IntDelegate (int x);
public delegate T[] TDelegate<T> ();
public class Gen<T> {
public int intFunction (int x) {
return x + 1;
}
public IntDelegate getIntDelegate () {
return intFunction;
}
public virtual int virtIntFunction (int x) {
return x + 2;
}
public IntDelegate getVirtIntDelegate () {
return virtIntFunction;
}
public T[] tFunction () {
return new T[3];
}
public TDelegate<T> getTDelegate () {
return tFunction;
}
public static T[] staticTFunction () {
return new T[3];
}
public TDelegate<T> getStaticTDelegate () {
return staticTFunction;
}
}
public class main {
public static int Main () {
Gen<ClassA> ga = new Gen<ClassA> ();
IntDelegate id = ga.getIntDelegate ();
TDelegate<ClassA> tda = ga.getTDelegate ();
IntDelegate vid = ga.getVirtIntDelegate ();
TDelegate<ClassA> stda = ga.getStaticTDelegate ();
if (id (123) != 124)
return 1;
if (tda ().GetType () != typeof (ClassA[]))
return 1;
if (vid (123) != 125)
return 1;
if (stda ().GetType () != typeof (ClassA[]))
return 1;
tda = (TDelegate<ClassA>)Delegate.CreateDelegate (typeof (TDelegate<ClassA>),
typeof (Gen<ClassA>).GetMethod ("staticTFunction"));
if (tda ().GetType () != typeof (ClassA[]))
return 1;
return 0;
}
}