Skip to content
Snippets Groups Projects
Commit 0ef86428 authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

Mo 22.11. Mehrdimensionale Felder

parent 43f82dcf
No related branches found
No related tags found
No related merge requests found
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_08_2D_Felder</RootNamespace>
</PropertyGroup>
</Project>
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;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_08_RefVsOut</RootNamespace>
</PropertyGroup>
</Project>
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;
}
}
}
...@@ -55,7 +55,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 Array_Anwendungen", "07 ...@@ -55,7 +55,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 Array_Anwendungen", "07
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 ArraysByRef", "07 ArraysByRef\07 ArraysByRef.csproj", "{20991EFE-5ABF-4176-B115-8430D4487392}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "07 ArraysByRef", "07 ArraysByRef\07 ArraysByRef.csproj", "{20991EFE-5ABF-4176-B115-8430D4487392}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -171,6 +175,14 @@ Global ...@@ -171,6 +175,14 @@ Global
{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}.Debug|Any CPU.Build.0 = Debug|Any CPU {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.ActiveCfg = Release|Any CPU
{982D3EE4-33F6-48B9-8E8A-68DCCDFA3A84}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment