2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / test-34.cs
blob60399d53be433ea1f04e3e8dcd25eb38b6cdcdea
1 //
2 // This test tests both how arguments are selected in the presence
3 // of ref/out modifiers and the params arguments.
4 //
5 using System;
7 public struct FancyInt {
8 public int value;
10 public FancyInt (int v)
12 value = v;
17 public class Blah {
18 static int got;
20 public static void Foo (ref int i, ref int j)
22 got = 1;
25 public static int Bar (int j, params int [] args)
27 got = 2;
28 int total = 0;
30 foreach (int i in args){
31 Console.WriteLine ("My argument: " + i);
32 total += i;
35 return total;
38 public static void Foo (int i, int j)
40 got = 3;
43 static void In (ref int a)
45 a++;
48 static void Out (ref int a)
50 In (ref a);
53 static int AddArray (params int [] valores)
55 int total = 0;
57 for (int i = 0; i < valores.Length; i++)
58 total += valores [i];
60 return total;
63 static int AddFancy (params FancyInt [] vals)
65 int total = 0;
67 for (int i = 0; i < vals.Length; i++)
68 total += vals [i].value;
70 return total;
74 public static int Main ()
76 int i = 1;
77 int j = 2;
79 int [] arr = new int [2] { 0, 1 };
81 Foo (i, j);
82 if (got != 3)
83 return 1;
85 Foo (ref i, ref j);
86 if (got != 1)
87 return 2;
89 if (Bar (i, j, 5, 4, 3, 3, 2) != 19)
90 return 4;
92 //if (Bar (1, arr) != 1)
93 // return 5;
95 if (got != 2)
96 return 3;
98 int k = 10;
100 Out (ref k);
101 if (k != 11)
102 return 10;
104 int [] arr2 = new int [2] {1, 2};
106 if (AddArray (arr2) != 3)
107 return 11;
109 FancyInt f_one = new FancyInt (1);
110 FancyInt f_two = new FancyInt (2);
112 if (AddFancy (f_one) != 1)
113 return 12;
115 if (AddFancy (f_one, f_two) != 3)
116 return 13;
118 Console.WriteLine ("Test passes");
119 return 0;