From 25d48a6946a6725fe31142f2f8c370f5a63b5135 Mon Sep 17 00:00:00 2001 From: "s.schueler.doz" Date: Tue, 11 Feb 2025 09:38:33 +0100 Subject: [PATCH] E18 - Ex 1 - 4 --- Exercises/E18_Methods/Exercise_1.cs | 2 +- Exercises/E18_Methods/Exercise_2.cs | 8 +++++++- Exercises/E18_Methods/Exercise_3.cs | 13 ++++++++++++- Exercises/E18_Methods/Exercise_4.cs | 10 ++++++++-- Exercises_C_Sharp_Lections.csproj | 2 +- lastPoint | 2 ++ 6 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 lastPoint diff --git a/Exercises/E18_Methods/Exercise_1.cs b/Exercises/E18_Methods/Exercise_1.cs index 8b12d08..09dab43 100644 --- a/Exercises/E18_Methods/Exercise_1.cs +++ b/Exercises/E18_Methods/Exercise_1.cs @@ -6,7 +6,7 @@ namespace Exercises_C_Sharp.E18_Methods { //Rufen Sie die unten stehende Methode auf. //Code START - + ShowImage(); //Code ENDE } diff --git a/Exercises/E18_Methods/Exercise_2.cs b/Exercises/E18_Methods/Exercise_2.cs index 1489c2a..530c790 100644 --- a/Exercises/E18_Methods/Exercise_2.cs +++ b/Exercises/E18_Methods/Exercise_2.cs @@ -6,11 +6,17 @@ namespace Exercises_C_Sharp.E18_Methods { //2. Rufen Sie die unten erstellte Methode auf. //Code START - + Superstart(); //Code ENDE } //Schreiben Sie eine Methode "Superstart", die auf der Konsole ein Begrüßungsfloskel ausgibt und zusätzlich noch auf die Konsole schreibt, dass das Programm gestartet wurde. //Code START + + static void Superstart() + { + Console.WriteLine("Hallo!"); + Console.WriteLine("Das Programm wurde gestartet....."); + } //Code ENDE diff --git a/Exercises/E18_Methods/Exercise_3.cs b/Exercises/E18_Methods/Exercise_3.cs index ced18a9..b118d0a 100644 --- a/Exercises/E18_Methods/Exercise_3.cs +++ b/Exercises/E18_Methods/Exercise_3.cs @@ -6,12 +6,23 @@ namespace Exercises_C_Sharp.E18_Methods { //2. Rufen Sie die unten erstellte Methode dreimal auf. Starten Sie mit dem Wert "13" und arbeiten Sie dann jeweils mit dem Rückgabewert weiter. //Code START + int l = 13; + for(int i = 0; i<3; i++) + l = Meth(l); + + Console.WriteLine("Ergebnis: " + l); + + //ODER: + + Console.WriteLine("Ergebnis: " + Meth(Meth(Meth(13)))); //Code ENDE } //Schreiben Sie eine Methode, die eine Übergebene Zahl verdoppelt und zurück gibt. //Code START - + + static int Meth(int zahl) => zahl * 2; + //Code ENDE } diff --git a/Exercises/E18_Methods/Exercise_4.cs b/Exercises/E18_Methods/Exercise_4.cs index 768184c..46afd58 100644 --- a/Exercises/E18_Methods/Exercise_4.cs +++ b/Exercises/E18_Methods/Exercise_4.cs @@ -6,12 +6,18 @@ namespace Exercises_C_Sharp.E18_Methods { //2. Rufen Sie die unten erstellte Methode auf und geben Sie den Inhalt auf der Konsole aus. //Code START - + Console.WriteLine(Meth()); //Code ENDE } //Erstellen Sie eine Methode, die bei jedem Aufruf zufällig eine von 10 Begrüßungen zurück gibt. //Code START - + static string Meth() + { + string[] arr = ["Hallo", "Hi", "Hey", "Hidiho", "Howdie", "Saluton", "Guten Tag", "Grüß Gott", "Servus", "Kein Interesse"]; + Random rand = new(); + + return arr[rand.Next(arr.Length)]; + } //Code ENDE } diff --git a/Exercises_C_Sharp_Lections.csproj b/Exercises_C_Sharp_Lections.csproj index f02677b..91b464a 100644 --- a/Exercises_C_Sharp_Lections.csproj +++ b/Exercises_C_Sharp_Lections.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable diff --git a/lastPoint b/lastPoint new file mode 100644 index 0000000..a97c770 --- /dev/null +++ b/lastPoint @@ -0,0 +1,2 @@ +3 +17