From 0ef864286cb3ac30c1479dd3bccc6cd5e2c329a0 Mon Sep 17 00:00:00 2001
From: Uwe Wienkop <uwe.wienkop@th-nuernberg.de>
Date: Mon, 22 Nov 2021 12:44:52 +0100
Subject: [PATCH] Mo 22.11. Mehrdimensionale Felder

---
 08 2D_Felder/08 2D_Felder.csproj |   9 +++
 08 2D_Felder/Program.cs          | 127 +++++++++++++++++++++++++++++++
 08 RefVsOut/08 RefVsOut.csproj   |   9 +++
 08 RefVsOut/Program.cs           |  30 ++++++++
 Prog1_WS2021_22.sln              |  14 +++-
 5 files changed, 188 insertions(+), 1 deletion(-)
 create mode 100644 08 2D_Felder/08 2D_Felder.csproj
 create mode 100644 08 2D_Felder/Program.cs
 create mode 100644 08 RefVsOut/08 RefVsOut.csproj
 create mode 100644 08 RefVsOut/Program.cs

diff --git a/08 2D_Felder/08 2D_Felder.csproj b/08 2D_Felder/08 2D_Felder.csproj
new file mode 100644
index 0000000..7636546
--- /dev/null
+++ b/08 2D_Felder/08 2D_Felder.csproj	
@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <RootNamespace>_08_2D_Felder</RootNamespace>
+  </PropertyGroup>
+
+</Project>
diff --git a/08 2D_Felder/Program.cs b/08 2D_Felder/Program.cs
new file mode 100644
index 0000000..02d1caa
--- /dev/null
+++ b/08 2D_Felder/Program.cs	
@@ -0,0 +1,127 @@
+using System;
+
+namespace _08_2D_Felder
+{
+    class Program
+    {
+        static void FeldAusgeben(int[,] feld)
+        {
+            for (int z = 0; z < feld.GetLength(0); z++)   // GetLength(n) ~ Anzahl der Elemente in der Dimension n
+            {
+                for (int i = 0; i < feld.GetLength(1); i++)
+                {
+                    Console.Write($"{feld[z, i],3}  ");
+                }
+                Console.WriteLine();
+            }
+            Console.WriteLine("-----------------------------");
+        }
+        static int[,] FeldKopieren(int[,] f1)
+        {
+            int[,] f2 = new int[f1.GetLength(0), f1.GetLength(1)];
+            for (int z = 0; z < f1.GetLength(0); z++)   // GetLength(n) ~ Anzahl der Elemente in der Dimension n
+                for (int i = 0; i < f1.GetLength(1); i++)
+                    f2[z,i] = f1[z, i];
+            return f2;
+        }
+        static void Main(string[] args)
+        {
+            int[] f1 = new int[10];     // int-Feld mit 10 Speicherplätzen
+            int[,] f2 = new int[3, 4];  // int-Feld mit 3 Zeilen zu je 4 Spalten
+            int[,,] f3 = new int[2, 3, 4]; // int-Feld mit 2 Ebenen mit jeweils 3 Zeilen zu je 4 Spalten
+
+            int[] g1 = { 1, 2, 3, 4, 5, 6 };
+            int[,] g2 = {
+                { 1,2,3},
+                { 4,5,6 }
+            };
+
+            for (int i = 0; i < g1.Length; i++)     // Length ~ Anzahl der Elemente im Feld
+            {
+                Console.Write($"{g1[i]}  ");
+            }
+            Console.WriteLine();
+            Console.WriteLine("--------------");
+
+            FeldAusgeben(g2);
+
+            int[,] h = new int[7, 18];
+            FeldAusgeben(h);
+
+            for (int z = 0; z < h.GetLength(0); z++)
+            {
+                for (int s = 0; s < h.GetLength(1); s++)    // .GetLength(1) ~ Anzahl der Spalten
+                    h[z, s] = (z+1)*100+s;
+            }
+            FeldAusgeben(h);
+
+
+            // Oberste Zeile mit 1 belegen:
+            for (int i = 0; i < h.GetLength(1); i++)    // .GetLength(1) ~ Anzahl der Spalten
+                h[0, i] = 1;
+            FeldAusgeben(h);
+
+
+            // Unterste Zeile mit 4 belegen:
+            for (int i = 0; i < h.GetLength(1); i++)    // .GetLength(1) ~ Anzahl der Spalten
+                h[h.GetLength(0)-1, i] = 4;
+            FeldAusgeben(h);
+
+            int[,] hh = FeldKopieren(h);
+
+            // Ganz linke Spalte mit 2 belegen:
+            for (int z = 1; z < h.GetLength(0)-1; z++)    // .GetLength(0) ~ Anzahl der Zeilen
+                h[z, 0] = 2;
+            FeldAusgeben(h);
+
+
+            // Ganz rechte Spalte mit 3 belegen:
+            for (int z = 0; z < h.GetLength(0); z++)    // .GetLength(0) ~ Anzahl der Zeilen
+                h[z, h.GetLength(1) - 1] = 3;
+            FeldAusgeben(h);
+
+
+            // Hauptdiagonale mit 5 belegen:
+            int min = Math.Min(h.GetLength(0), h.GetLength(1));
+            for (int i = 0; i < min; i++)    
+                h[i, i] = 5;
+            FeldAusgeben(h);
+
+
+            ///////////////////////////////////////////////////////////////////////////
+            /// Ausgefranste Felder (Jagged Arrays)
+
+            int[][] k = new int[5][];
+            k[0] = new int[5];
+            k[1] = new int[1];
+            k[3] = new int[] { 4, 5, 6, 7, 8, 9, 3 };
+
+            for (int z = 0; z < k.Length; z++)
+            {
+                if (k[z] != null)
+                {
+                    for (int i = 0; i < k[z].Length; i++)
+                    {
+                        Console.Write($"{k[z][i]} ");
+                    }
+                    Console.WriteLine();
+                }
+                else
+                {
+                    Console.WriteLine("Null - Zeile");
+                }
+            }
+
+
+
+            /////////////////////////////////////////////////////////////////////
+            ///
+            int anz = 6;
+            bool[] bf = new bool[1000000];
+
+            for (int i = 0; i < bf.Length; i++)
+                bf[i] = true;
+
+        }
+    }
+}
diff --git a/08 RefVsOut/08 RefVsOut.csproj b/08 RefVsOut/08 RefVsOut.csproj
new file mode 100644
index 0000000..312070a
--- /dev/null
+++ b/08 RefVsOut/08 RefVsOut.csproj	
@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <RootNamespace>_08_RefVsOut</RootNamespace>
+  </PropertyGroup>
+
+</Project>
diff --git a/08 RefVsOut/Program.cs b/08 RefVsOut/Program.cs
new file mode 100644
index 0000000..cf989c0
--- /dev/null
+++ b/08 RefVsOut/Program.cs	
@@ -0,0 +1,30 @@
+using System;
+
+namespace _08_RefVsOut
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            int x=3;
+            int y=5;
+            TueEtwas(ref x,out y);
+
+            LängeBreitengrad2XY(2, 3, out double a, out double b);
+            Console.WriteLine($"{a}, {b}");
+        }
+        static void LängeBreitengrad2XY(double laengengrad, double breitengrad, out double X, out double Y)
+        {
+            // :
+            X = 123;
+            Y = 456;
+        }
+        static void TueEtwas(ref int a, out int b)
+        {
+            int xx;
+            //xx = b * b;
+            xx = a * a;
+            b = 5;
+        }
+    }
+}
diff --git a/Prog1_WS2021_22.sln b/Prog1_WS2021_22.sln
index 186374f..a3378c6 100644
--- a/Prog1_WS2021_22.sln
+++ b/Prog1_WS2021_22.sln
@@ -55,7 +55,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 Array_Anwendungen", "07
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 ArraysByRef", "07 ArraysByRef\07 ArraysByRef.csproj", "{20991EFE-5ABF-4176-B115-8430D4487392}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "07 DoubleUngenauigkeiten", "07 DoubleUngenauigkeiten\07 DoubleUngenauigkeiten.csproj", "{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 DoubleUngenauigkeiten", "07 DoubleUngenauigkeiten\07 DoubleUngenauigkeiten.csproj", "{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "08 RefVsOut", "08 RefVsOut\08 RefVsOut.csproj", "{4724CACD-310A-4F71-B140-400D77C92EC7}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "08 2D_Felder", "08 2D_Felder\08 2D_Felder.csproj", "{EE89CDF4-D279-4F6D-82E0-26175D60DF5D}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -171,6 +175,14 @@ Global
 		{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}.Release|Any CPU.Build.0 = Release|Any CPU
+		{4724CACD-310A-4F71-B140-400D77C92EC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{4724CACD-310A-4F71-B140-400D77C92EC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{4724CACD-310A-4F71-B140-400D77C92EC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{4724CACD-310A-4F71-B140-400D77C92EC7}.Release|Any CPU.Build.0 = Release|Any CPU
+		{EE89CDF4-D279-4F6D-82E0-26175D60DF5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{EE89CDF4-D279-4F6D-82E0-26175D60DF5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{EE89CDF4-D279-4F6D-82E0-26175D60DF5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{EE89CDF4-D279-4F6D-82E0-26175D60DF5D}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
-- 
GitLab