public static void OutParameter() { //Umständliche Variante der Swap-Methode mit Tuples string wort1 = "Wort1"; string wort2 = "Wort2"; Tuple <string, string> result = GenerischeMethoden.SwapTuple <string>(wort1, wort2); wort1 = result.Item2; wort2 = result.Item1; //Eingabe wird solange wiederholt, bis die richtige Zahl eingegeben wurde int geparsteZahl; while (!int.TryParse(Console.ReadLine(), out geparsteZahl)) { Console.WriteLine("Zahl konnte nicht geparst werden. Geben Sie eine neue ein: "); } Console.WriteLine($"geparste Zahl: {geparsteZahl}"); }
private static void TesteGenerischeMethoden() { Console.WriteLine("-----TesteGenerischeMethoden-----"); int zahl = 5; int zahl2 = 10; //GenerischeMethoden.Swap<int>(ref zahl, ref zahl2); //Project->Properties->Build->Advanced->C# Version auf 7.2!! zahl.SwapExt(ref zahl2); Console.WriteLine($"Zahl1: {zahl}"); Console.WriteLine($"Zahl2: {zahl2}"); string wort1 = "Wort1"; string wort2 = "Wort2"; GenerischeMethoden.Swap(ref wort1, ref wort2); //GenerischeMethoden.SwapOut<string>(wort1, wort2, out wort1, out wort2); Console.WriteLine($"Wort1: {wort1}"); Console.WriteLine($"Wort2: {wort2}"); }