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

2022-01-10 Mo

parent 24602d80
No related branches found
No related tags found
No related merge requests found
......@@ -9,11 +9,11 @@ namespace _04_Schachbrett
bool schwarz = true;
string schwarzFeld = "XXXXX";
string weissFeld = " ";
for (int z = 0; z < 8; z++)
for (int z = 0; z < 8; z++) // Zeilenschleife
{
for (int n = 0; n < 3; n++)
for (int n = 0; n < 3; n++) // Wiederholungen der jeweiligen Zeile
{
for (int s = 0; s < 8; s++)
for (int s = 0; s < 8; s++) // Schleife über die Spalten der jeweiligen Zeile
{
if (schwarz)
Console.Write(schwarzFeld);
......
......@@ -92,7 +92,7 @@ namespace _08_2D_Felder
/// Ausgefranste Felder (Jagged Arrays)
/// Feld von Feldern
int[][] k = new int[5][]; // 5er Feld von ...
int[][] k = new int[5][]; // 5er Feld von ... 1D-Feldern
k[0] = new int[5]; // Feld an der Zeilen-Pos. 0
k[1] = new int[1];
k[3] = new int[] { 4, 5, 6, 7, 8, 9, 3 };
......
......@@ -7,24 +7,34 @@ namespace _08_RefVsOut
static void Main(string[] args)
{
int x=3;
int y=5;
TueEtwas(ref x,out y);
int y1=5;
int y2 = 5;
TueEtwas(ref x,out y1, out y2);
LängeBreitengrad2XY(2, 3, out double a, out double b);
LängeBreitengrad2XY(11, 48, out double a, out double b);
Console.WriteLine($"{a}, {b}");
}
// Längengrad und Breitengrad werden per call-by-value übergeben
// X UND Y sollen zurückgeliefert werden
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)
// ref UND out stehen für eine Parameterübergabe per Referenz
// ref ~ diese Variable wurde in der aufrufenden Funktion bereits initialisiert
// out ~ diese Variable wird in DIESER Funktion initialisiert; muss nicht zwingend
// initialisiert übergeben werden
static void TueEtwas(ref int a, out int b1, out int b2)
{
int xx;
//xx = b * b;
//xx = b1 * b1; // nicht zulässig, da b nicht notwendig initialisiert sein muss
xx = a * a;
b = 5;
b1 = 5; // ALLE out-Parametervariablen müssen in der Funktion
b2 = 5; // einen Wert erhalten
}
}
}
......@@ -22,6 +22,17 @@ namespace _09_Contains_UebgMo
}
return false; // Der enthalten-String kommt an keiner Position (vollständig) vor
}
static bool StartsWith(string s, string enthalten)
{
for (int j = 0; j < enthalten.Length; j++) // Schleife über enthalten-String
{
if (char.ToLower(s[j]) != char.ToLower(enthalten[j])) // Tolerieren von Groß- und Kleinschreibung
return false;
}
return true; // Alle Zeichen (ohne Abbruch) getestet --> StartWith=true
}
static void ContainsTest(string s1, string s2)
{
Console.WriteLine($"{s1,20} enthält {s2,-15} {Contains(s1,s2)}");
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_13_DiesUndDas</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _13_DiesUndDas
{
class Program
{
static void Main(string[] args)
{
string s1 = "Datei 1";
string s2 = "Dateix";
string s3 = "123";
s3 += (char) 45;
Console.WriteLine(s3);
int y = 2;
double x = (y<10) ? 5 : 3.1;
y--; // Kein Unterschied bei alleinstehender Verwendung
--y;
y = 3;
int[] f = new int[10];
// entweder
f[y--] = 10; // f[3] = 10; y--; --> y=2;
// oder
f[--y] = 10; // y--; --> y=2; f[2] = 10;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_13_SchriftlichAddieren</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _13_SchriftlichAddieren
{
class Program
{
static string Addiere(string z1, string z2)
{
// return (Convert.ToInt32(z1) + Convert.ToInt32(z2)).ToString();
// 59
// 64
// ---
// 123
string erg = "";
int uebertrag = 0;
for (int i = z1.Length-1; i >= 0; i--)
{
int sum = (z1[i] - '0') + (z2[i] - '0') + uebertrag; // '9' --> 9; '4' --> 4; sum = 9+4 = 13
erg = (char) (sum % 10 + '0') + erg; // 3 + '0' --> '3'
uebertrag = sum / 10;
}
if (uebertrag == 1)
erg = "1" + erg;
return erg;
}
static void Main(string[] args)
{
Console.WriteLine(Addiere("59595959595959595959", "59595959595959595959"));
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_13_StructPersonalausweis</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _13_StructPersonalausweis
{
struct Personalausweis
{
public string name, vorname;
public int id;
public Personalausweis(string Name, string Vorname, int Id)
{
name = Name;
vorname = Vorname;
id = Id;
}
public override string ToString()
{
string vollname = name + ", " + vorname;
return $"{vollname,-30} ID: {id}";
}
}
class Program
{
static Personalausweis NeuerPersonalausweis(string Name, string Vorname, int Id)
{
Personalausweis persoNeu;
persoNeu.name = Name;
persoNeu.vorname = Vorname;
persoNeu.id = Id;
return persoNeu;
}
static string PersoToString(Personalausweis p)
{
string vollname = p.name + ", " + p.vorname;
return $"{vollname,-30} ID: {p.id}";
}
static void Main(string[] args)
{
Personalausweis p1 = NeuerPersonalausweis("Wienkop", "Uwe", 1000);
Personalausweis p2 = NeuerPersonalausweis("Huber", "Anton", 1001);
Console.WriteLine(p1);
Console.WriteLine($"Name: {p1.name}, {p1.vorname} ID: {p1.id}");
Console.WriteLine(PersoToString(p1));
Console.WriteLine(PersoToString(p2));
Console.WriteLine("-----");
Console.WriteLine(p1);
Console.WriteLine(p2);
}
}
}
......@@ -123,13 +123,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 StructBruch", "12 Struct
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 StringConcat", "12 StringConcat\12 StringConcat.csproj", "{B4191FF6-95B7-4577-AE98-9B42BC338F5A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 Strings", "12 Strings\12 Strings.csproj", "{F734F09D-F050-47AB-9A61-36598C31FA62}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 Strings", "12 Strings\12 Strings.csproj", "{F734F09D-F050-47AB-9A61-36598C31FA62}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 Fibonacci", "12 Fibonacci\12 Fibonacci.csproj", "{5D02394C-9622-41A8-A54C-6E86820824CF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 Fibonacci", "12 Fibonacci\12 Fibonacci.csproj", "{5D02394C-9622-41A8-A54C-6E86820824CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 StructLehrveranstaltungsplanung", "12 StructLehrveranstaltungsplanung\12 StructLehrveranstaltungsplanung.csproj", "{1CF6FDB2-DAE5-42CF-8658-2CDE81918344}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 StructLehrveranstaltungsplanung", "12 StructLehrveranstaltungsplanung\12 StructLehrveranstaltungsplanung.csproj", "{1CF6FDB2-DAE5-42CF-8658-2CDE81918344}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 Mediendaten (alte Klausur)", "12 Mediendaten (alte Klausur)\12 Mediendaten (alte Klausur).csproj", "{6009194F-17E8-4EAA-B29E-47FA15EC53C9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 Mediendaten (alte Klausur)", "12 Mediendaten (alte Klausur)\12 Mediendaten (alte Klausur).csproj", "{6009194F-17E8-4EAA-B29E-47FA15EC53C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 DiesUndDas", "13 DiesUndDas\13 DiesUndDas.csproj", "{CB47C423-B137-4CFB-A535-AF9C74323C00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 SchriftlichAddieren", "13 SchriftlichAddieren\13 SchriftlichAddieren.csproj", "{8E73624E-93CD-4670-B8E9-408F4385F686}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 StructPersonalausweis", "13 StructPersonalausweis\13 StructPersonalausweis.csproj", "{3E44868E-6C68-4080-A071-94EDD05624AD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -393,6 +399,18 @@ Global
{6009194F-17E8-4EAA-B29E-47FA15EC53C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6009194F-17E8-4EAA-B29E-47FA15EC53C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6009194F-17E8-4EAA-B29E-47FA15EC53C9}.Release|Any CPU.Build.0 = Release|Any CPU
{CB47C423-B137-4CFB-A535-AF9C74323C00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB47C423-B137-4CFB-A535-AF9C74323C00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB47C423-B137-4CFB-A535-AF9C74323C00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB47C423-B137-4CFB-A535-AF9C74323C00}.Release|Any CPU.Build.0 = Release|Any CPU
{8E73624E-93CD-4670-B8E9-408F4385F686}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E73624E-93CD-4670-B8E9-408F4385F686}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E73624E-93CD-4670-B8E9-408F4385F686}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E73624E-93CD-4670-B8E9-408F4385F686}.Release|Any CPU.Build.0 = Release|Any CPU
{3E44868E-6C68-4080-A071-94EDD05624AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E44868E-6C68-4080-A071-94EDD05624AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E44868E-6C68-4080-A071-94EDD05624AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E44868E-6C68-4080-A071-94EDD05624AD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment