123
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 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CustomGenerics { class Program { static void Main(string[] args) { int a = 1; int b = 2; Swap<int>(ref a,ref b); Console.WriteLine(a+""+b); string s1 = "1"; string s2 = "2"; Swap<string>(ref s1, ref s2); Console.WriteLine(s1 + "" + s2); Console.ReadLine(); } static void Swap<T>(ref T a, ref T b) { T temp; temp = a; a = b; b = temp; } } } |