28
1
using System;
2
3
public class Maths {
4
5
public static void Swap<T>(ref T a, ref T b) {
6
T temp = a;
7
a = b;
8
b = temp;
9
}
10
}
11
12
public class Program {
13
public static void Main() {
14
int twenty = 20;
15
int thirty = 30;
16
string forty = "forty";
17
string fifty = "fifty";
18
19
Maths.Swap<int>(ref twenty, ref thirty);
20
Console.WriteLine("twenty = {0}", twenty);
21
Console.WriteLine("thirty = {0}", thirty);
22
23
Maths.Swap<string>(ref forty, ref fifty);
24
Console.WriteLine("forty = {0}", forty);
25
Console.WriteLine("fifty = {0}", fifty);
26
27
}
28
}
Cached Result