File: test-26.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (72 lines) | stat: -rw-r--r-- 1,054 bytes parent folder | download | duplicates (13)
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
68
69
70
71
72
using System;

public class Blah {

	public delegate int MyDelegate (int i, int j);
	
	public int Foo (int i, int j)
	{
		return i+j;
	}

	public static int Test1 ()
	{
		Blah f = new Blah ();

		MyDelegate del = new MyDelegate (f.Foo);

		MyDelegate another = new MyDelegate (del);

		int number = del (2, 3);

		int i = another (4, 6);
		
		Console.WriteLine ("Delegate invocation of one returned : " + number);

		Console.WriteLine ("Delegate invocation of the other returned : " + i);

		if (number == 5 && i == 10)
			return 0;
		else
			return 1;
	}
	
	public delegate int List (params int [] args);

	public static int Adder (params int [] args)
	{
		int total = 0;
		
		foreach (int i in args)
			total += i;

		return total;
	}

	public static int Test2 ()
	{
		List my_adder = new List (Adder);

		if (my_adder (1, 2, 3) != 6)
			return 2;

		return 0;
	}
	
	public static int Main ()
	{
		int v;

		v = Test1 ();
		if (v != 0)
			return v;

		v = Test2 ();
		if (v != 0)
			return v;

		Console.WriteLine ("All tests pass");
		return 0;
	}

}