diff --git a/11-3 Erweiterungsmethoden/11-3 Erweiterungsmethoden.csproj b/11-3 Erweiterungsmethoden/11-3 Erweiterungsmethoden.csproj new file mode 100644 index 0000000000000000000000000000000000000000..77c8727b638b80b96c45f4ae4058b1992a1273a5 --- /dev/null +++ b/11-3 Erweiterungsmethoden/11-3 Erweiterungsmethoden.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_11_3_Erweiterungsmethoden</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/11-3 Erweiterungsmethoden/Program.cs b/11-3 Erweiterungsmethoden/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..5e202a9c1c9fa1f0ec886be7851749464c590499 --- /dev/null +++ b/11-3 Erweiterungsmethoden/Program.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; + +namespace _11_3_Erweiterungsmethoden +{ + public static class Erweiterung + { + public static int Abs(this int i) + => (i > 0) ? i : -i; + + public static T[] Sortieren<T> (this T[] feld) where T:IComparable<T> + { + // ... Hier Ihre Sort-Methode + Array.Sort(feld); + return feld; + } + } + class Program + { + static void Main(string[] args) + { + int ix = -25; + //Console.WriteLine(ix.Abs()); + + int[] ints = { 10, 45, 15, 38, 21, 26 }; + var res = ints.Sortieren(); + foreach (var item in res) + { + Console.WriteLine(item); + } + + Console.WriteLine("---------"); + var res2 = ints.OrderBy(g=>-g); + foreach (var item in res2) + { + Console.WriteLine(item); + } + } + } +} diff --git a/11-4 LINQ-Intro/11-4 LINQ-Intro.csproj b/11-4 LINQ-Intro/11-4 LINQ-Intro.csproj new file mode 100644 index 0000000000000000000000000000000000000000..a123c7968e2872f64160fa00efa83ee511f12ac1 --- /dev/null +++ b/11-4 LINQ-Intro/11-4 LINQ-Intro.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_11_4_LINQ_Intro</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/11-4 LINQ-Intro/Program.cs b/11-4 LINQ-Intro/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..3b97dddbe3c937913e58abe5ef49c422241d33cd --- /dev/null +++ b/11-4 LINQ-Intro/Program.cs @@ -0,0 +1,66 @@ +using System; +using System.Linq; + +namespace _11_4_LINQ_Intro +{ + class AnonymeVariableImProperty + { + public int MeinProperty { get; set; } + } + + class AnonymeTypen + { + public static void AnonymousTypes() + { + #region var + var x = "123"; + //x = 123; + + object o = 123; + o = "123"; + #endregion + var r1 = new { Name = "Wienkop", Tel = 1614, Adr = "Hohfederstraße 40" }; + var r2 = new { Name = "Wienkop", Tel = 1614}; + + Console.WriteLine(r1); + Console.WriteLine(r2.Name); + // r1.Name = r2.Name; Nicht zulässig, die Properties sind read-only! + + var r3 = new { Name = r1.Name, AdrLaenge = r1.Adr.Length }; + Console.WriteLine(r3); + } + } + class Program + { + static void Main(string[] args) + { + // AnonymeTypen.AnonymousTypes(); + + string[] wörter = { + "Anton", "Berta", "Charles", "Dieter", "Emma", "Franz", "Gustav", "Heiner", "Ida", + "Johanna", "Klaus", "Ludwig", "Manni", "Norbert", "Otto", "Paul", "Quasimodo", "Rainer", + "Stefan", "Thorsten", "Uwe", "Victoria", "Willi", "Xaver", "Yvonne", "Zacharias" + }; + //var r1 = from w in wörter + // where w.Length < 6 + // orderby w descending + // select new { OrgName = w, GrossName = w.ToUpper(), Länge = w.Length }; + //foreach (var item in r1) + //{ + // Console.WriteLine(item); + //} + + var r2 = from w in wörter + where w.Length < 7 + group w by w.Length; + foreach (var group in r2) + { + Console.WriteLine($"Länge: {group.Key}"); + foreach (var item in group) + { + Console.WriteLine(item); + } + } + } + } +} diff --git a/11-5 BinTreePersVerwaltung/.editorconfig b/11-5 BinTreePersVerwaltung/.editorconfig new file mode 100644 index 0000000000000000000000000000000000000000..2edebbfd16744470f091c09a9d15734c3b0dbc91 --- /dev/null +++ b/11-5 BinTreePersVerwaltung/.editorconfig @@ -0,0 +1,32 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\wienkop\source\repos\prog2-ss2021-wienkop\11-5 BinTreePersVerwaltung\ codebase based on best match to current usage at 08.06.2021 +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Core editorconfig formatting - indentation + +#use soft tabs (spaces) for indentation +indent_style = space + +#Formatting - spacing options + +#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call +csharp_space_between_method_call_parameter_list_parentheses = false +#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. +csharp_space_between_method_declaration_parameter_list_parentheses = false + +#Style - expression bodied member options + +#prefer block bodies for methods +csharp_style_expression_bodied_methods = false:suggestion + +#Style - language keyword and framework type options + +#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion + +#Style - modifier options + +#do not prefer accessibility modifiers to be specified +dotnet_style_require_accessibility_modifiers = never:suggestion diff --git a/11-5 BinTreePersVerwaltung/11-5 BinTreePersVerwaltung.csproj b/11-5 BinTreePersVerwaltung/11-5 BinTreePersVerwaltung.csproj new file mode 100644 index 0000000000000000000000000000000000000000..cf12192798bc43d174a056573e753f3a9ae345c1 --- /dev/null +++ b/11-5 BinTreePersVerwaltung/11-5 BinTreePersVerwaltung.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_11_5_BinTreePersVerwaltung</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/11-5 BinTreePersVerwaltung/Personal.cs b/11-5 BinTreePersVerwaltung/Personal.cs new file mode 100644 index 0000000000000000000000000000000000000000..e93ee449b25c42a1493efb06b42af7d7f38c2ab8 --- /dev/null +++ b/11-5 BinTreePersVerwaltung/Personal.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace _11_5_BinTreePersVerwaltung +{ + abstract class Personal + { + public string Name { get; set; } + public Personal (string Name) { this.Name = Name; } + abstract public double Kosten { get; } + } + class Mitarbeiter : Personal + { + protected double gehalt; + public Mitarbeiter(string Name, double Gehalt) : base(Name) { gehalt = Gehalt; } + public override double Kosten { get => 12.65 * gehalt; } + } + class Führungskraft : Personal + { + protected double gehalt; + protected double erfolgsbeteiligung; + public Führungskraft (string Name, double Gehalt, double Erfolgsbeteiligung) : base (Name) + { + gehalt = Gehalt; + erfolgsbeteiligung = Erfolgsbeteiligung; + } + public override double Kosten { get => 12.65 * gehalt + erfolgsbeteiligung; } + } + class Werkvertragler : Personal + { + protected double betrag; + public Werkvertragler(string Name, double Betrag) : base (Name) + { + betrag = Betrag; + } + public override double Kosten { get => betrag; } + } +} diff --git a/11-5 BinTreePersVerwaltung/Program.cs b/11-5 BinTreePersVerwaltung/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..92edc87a4cdcaf696feead291710eef9cabd5d82 --- /dev/null +++ b/11-5 BinTreePersVerwaltung/Program.cs @@ -0,0 +1,17 @@ +using System; + +namespace _11_5_BinTreePersVerwaltung +{ + class Program + { + static void Main(string[] args) + { + Personal[] persFeld = new Personal[10]; + persFeld[0] = new Mitarbeiter("Xaver", 3000); + foreach (var item in persFeld) + { + Console.WriteLine(item.Kosten); + } + } + } +} diff --git a/11-Ubg Mailverteiler-Di/11-Ubg Mailverteiler-Di.csproj b/11-Ubg Mailverteiler-Di/11-Ubg Mailverteiler-Di.csproj new file mode 100644 index 0000000000000000000000000000000000000000..9e93c55cd25901d383cbb3022bfd4553d3daa709 --- /dev/null +++ b/11-Ubg Mailverteiler-Di/11-Ubg Mailverteiler-Di.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_11_Ubg_Mailverteiler_Di</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/11-Ubg Mailverteiler-Di/MessageBox.cs b/11-Ubg Mailverteiler-Di/MessageBox.cs new file mode 100644 index 0000000000000000000000000000000000000000..d680ed0a64aad45c924c6bd3f31cd9da8d82c66a --- /dev/null +++ b/11-Ubg Mailverteiler-Di/MessageBox.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace _11_Ubg_Mailverteiler_Di +{ + // Legen Sie ein Delegate void Callback(string s) an + // Erstellen Sie eine Klasse MessageBox mit + // - Einem Event Verteiler + // - Einer Methode Send(string s), welche die verteiler Variable aufruft + + // Experimentieren Sie ... + // 1) Legen Sie zwei Dummy-Klassen ClassA und ClassB an. Beide Klassen sollen öffentliche Methoden + // (statisch/nicht-statisch) besitzen, die der Callback-Signatur entsprechen + // 2) Definieren Sie auch in Main noch eine statische Methode, die der Callback-Signatur entspricht + // 3) Legen Sie eine Instanz der MessageBox an und registrieren Sie die Methoden in der Event-Variablen + // 4) Rufen Sie Send() mit einem Text auf + // 5) Entfernen Sie eine der registrierten Methoden und geben Sie noch einen Text aus + + class MessageBox + { + public delegate void Callback(string s); + public delegate void TransformDel(ref string s); + + public event Callback Verteiler; + public event TransformDel Transformationen; + + public void Send(string s) + { + Transformationen?.Invoke(ref s); + Verteiler?.Invoke(s); + } + } +} diff --git a/11-Ubg Mailverteiler-Di/Program.cs b/11-Ubg Mailverteiler-Di/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..bc9cc5f34ba68dccc8272874852b05c37e3e8955 --- /dev/null +++ b/11-Ubg Mailverteiler-Di/Program.cs @@ -0,0 +1,46 @@ +using System; + +namespace _11_Ubg_Mailverteiler_Di +{ + class DummyA + { + public static void ToUpperAusgabe(string s) + { + Console.WriteLine(s.ToUpper()); + } + public static void ToUpper(ref string s) + { + s = s.ToUpper(); + } + } + class DummyB + { + public int x = 0; + public void Bereich(string s) + { + Console.WriteLine($"x: {x} --{s.Substring(6)}"); + } + } + class Program + { + static void Ausgabe(string s) + { + Console.WriteLine(s); + } + static void Main(string[] args) + { + MessageBox mb = new MessageBox(); + DummyB [] db = new DummyB[10]; + db[1] = new DummyB(); + db[1].x = 99; + mb.Verteiler += Program.Ausgabe; + mb.Verteiler += DummyA.ToUpperAusgabe; + mb.Verteiler += db[1].Bereich; + + mb.Transformationen += DummyA.ToUpper; + + mb.Send("Hallo Welt"); + //mb.Verteiler("Hallo"); + } + } +} diff --git a/12Delegateaufrufausbreitung/12Delegateaufrufausbreitung.csproj b/12Delegateaufrufausbreitung/12Delegateaufrufausbreitung.csproj new file mode 100644 index 0000000000000000000000000000000000000000..c73e0d1692ab38cc8596bbd32ae080d903aaa778 --- /dev/null +++ b/12Delegateaufrufausbreitung/12Delegateaufrufausbreitung.csproj @@ -0,0 +1,8 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + </PropertyGroup> + +</Project> diff --git a/12Delegateaufrufausbreitung/Program.cs b/12Delegateaufrufausbreitung/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..acd45d215a8afe0eff9eba63fb760415a52e59f0 --- /dev/null +++ b/12Delegateaufrufausbreitung/Program.cs @@ -0,0 +1,136 @@ +using System; + +namespace SS2020Test +{ + delegate void myDelegate(bool x); + //delegate int myLogic(int x, int y); + abstract class LogicElement + { + bool[] inputs; + bool out1; + string me; + public LogicElement(int count, string me) + { + inputs = new bool[count]; + this.me = me; + Update(); + } + public event myDelegate Output; + + public abstract bool Logic(bool x, bool y); + + private void Input(int idx, bool val) + { + Console.Write($"<{me} = {val} | {out1} "); + inputs[idx] = val; + Update(); + Console.WriteLine($"--> {out1}>"); + Output?.Invoke(out1); + } + private void Update() + { + out1 = (inputs.Length == 2) ? + Logic(inputs[0], inputs[1]) : Logic(inputs[0], inputs[0]); + } + public void Input1(bool in1) { Input(0, in1); } + public void Input2(bool in2) { Input(1, in2); } + public override string ToString() => $"[{me}]: {out1}"; + } + class AndGate : LogicElement + { + public AndGate(string me) : base(2, me) { } + public override bool Logic(bool in1, bool in2) => in1 && in2 ? true : false; + } + class OrGate : LogicElement + { + public OrGate(string me) : base(2, me) { } + public override bool Logic(bool in1, bool in2) => in1 == false && in2 == false ? false : true; + } + + class NotGate : LogicElement + { + public NotGate(string me) : base(1, me) { } + public override bool Logic(bool in1, bool in2) => !in1; + } + class Port : LogicElement + { + public Port(string me) : base(1, me) { } + public bool Input { set { Input1(value); } } + public override bool Logic(bool in1, bool in2) => in1; + } + class HalfAdder + { + public Port portX = new Port("x"); + public Port portY = new Port("y"); + public AndGate carry = new AndGate("cy "); + public OrGate sum = new OrGate("sum"); + string me; + + NotGate notX = new NotGate("nx"); + NotGate notY = new NotGate("ny"); + + AndGate a1 = new AndGate("a1"); + AndGate a2 = new AndGate("a2"); + public HalfAdder(string me) + { + this.me = me; + portX.Output += notX.Input1; + portX.Output += a2.Input1; + portX.Output += carry.Input1; + + portY.Output += notY.Input1; + portY.Output += a1.Input2; + portY.Output += carry.Input2; + + notX.Output += a1.Input1; + notY.Output += a2.Input2; + + a1.Output += sum.Input1; + a2.Output += sum.Input2; + } + } + class FullAdder + { + public Port portA = new Port("a"); + public Port portB = new Port("b"); + public Port portC = new Port("cIn"); + + private HalfAdder FAsum = new HalfAdder("sum"); + private HalfAdder ha1 = new HalfAdder("HA"); + private OrGate carry = new OrGate("cy "); + private string me; + public FullAdder(string me) + { + this.me = me; + portA.Output += ha1.portX.Input1; + portB.Output += ha1.portY.Input1; + portC.Output += FAsum.portX.Input1; + + ha1.carry.Output += carry.Input2; + ha1.sum.Output += FAsum.portY.Input1; + portC.Output += FAsum.portX.Input1; + + FAsum.carry.Output += carry.Input1; + } + class Program + { + + static void Main(string[] args) + { + FullAdder fa = new FullAdder("FA"); + fa.portA.Input = false; + fa.portB.Input = true; + fa.portC.Input = false; + Console.WriteLine($"\n{ fa.FAsum.sum,12} | {fa.carry}"); + + fa.portC.Input = true; + Console.WriteLine($"\n{ fa.FAsum.sum,12} | {fa.carry}"); + + fa.portA.Input = true; + Console.WriteLine($"\n{ fa.FAsum.sum,12} | {fa.carry}"); + + + } + } + } +} diff --git a/Prog2WienkopSS2021.sln b/Prog2WienkopSS2021.sln index dc3125553e27c60d3c284f00088552f076e0268a..3dcfaefdbb56e59df703cb10c2e547418d1edb9a 100644 --- a/Prog2WienkopSS2021.sln +++ b/Prog2WienkopSS2021.sln @@ -85,11 +85,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "10-Ubg HashDict-Di", "10-Ub EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "10-3 WpfButton", "10-3 WpfButton\10-3 WpfButton.csproj", "{11636803-CB01-4A29-ADAE-F03F3F38ED70}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-Ubg Mailverteiler-Mo", "11-Ubg Mailverteiler-Mo\11-Ubg Mailverteiler-Mo.csproj", "{C36B7276-D500-4147-853C-9B90418514B1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11-Ubg Mailverteiler-Mo", "11-Ubg Mailverteiler-Mo\11-Ubg Mailverteiler-Mo.csproj", "{C36B7276-D500-4147-853C-9B90418514B1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-1 DataDriven", "11-1 DataDriven\11-1 DataDriven.csproj", "{0799E33E-C645-4CBD-BD98-623E290E947C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11-1 DataDriven", "11-1 DataDriven\11-1 DataDriven.csproj", "{0799E33E-C645-4CBD-BD98-623E290E947C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-2 Delegate Verkettung", "11-2 Delegate Verkettung\11-2 Delegate Verkettung.csproj", "{0FC3EC66-BD2E-46C4-8512-FB1DFD6A62F8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11-2 Delegate Verkettung", "11-2 Delegate Verkettung\11-2 Delegate Verkettung.csproj", "{0FC3EC66-BD2E-46C4-8512-FB1DFD6A62F8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-Ubg Mailverteiler-Di", "11-Ubg Mailverteiler-Di\11-Ubg Mailverteiler-Di.csproj", "{A602EA3B-7F14-4D94-B519-D3BD870CA1DA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-3 Erweiterungsmethoden", "11-3 Erweiterungsmethoden\11-3 Erweiterungsmethoden.csproj", "{64AE6304-67E0-4413-8D66-D12B3C133D09}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-4 LINQ-Intro", "11-4 LINQ-Intro\11-4 LINQ-Intro.csproj", "{7B612E44-F4A4-4857-BCAE-6DA1045A4FDE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11-5 BinTreePersVerwaltung", "11-5 BinTreePersVerwaltung\11-5 BinTreePersVerwaltung.csproj", "{FEC9D71A-A142-4EB5-920F-170DAD90F352}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -273,6 +281,22 @@ Global {0FC3EC66-BD2E-46C4-8512-FB1DFD6A62F8}.Debug|Any CPU.Build.0 = Debug|Any CPU {0FC3EC66-BD2E-46C4-8512-FB1DFD6A62F8}.Release|Any CPU.ActiveCfg = Release|Any CPU {0FC3EC66-BD2E-46C4-8512-FB1DFD6A62F8}.Release|Any CPU.Build.0 = Release|Any CPU + {A602EA3B-7F14-4D94-B519-D3BD870CA1DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A602EA3B-7F14-4D94-B519-D3BD870CA1DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A602EA3B-7F14-4D94-B519-D3BD870CA1DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A602EA3B-7F14-4D94-B519-D3BD870CA1DA}.Release|Any CPU.Build.0 = Release|Any CPU + {64AE6304-67E0-4413-8D66-D12B3C133D09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64AE6304-67E0-4413-8D66-D12B3C133D09}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64AE6304-67E0-4413-8D66-D12B3C133D09}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64AE6304-67E0-4413-8D66-D12B3C133D09}.Release|Any CPU.Build.0 = Release|Any CPU + {7B612E44-F4A4-4857-BCAE-6DA1045A4FDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B612E44-F4A4-4857-BCAE-6DA1045A4FDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B612E44-F4A4-4857-BCAE-6DA1045A4FDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B612E44-F4A4-4857-BCAE-6DA1045A4FDE}.Release|Any CPU.Build.0 = Release|Any CPU + {FEC9D71A-A142-4EB5-920F-170DAD90F352}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FEC9D71A-A142-4EB5-920F-170DAD90F352}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FEC9D71A-A142-4EB5-920F-170DAD90F352}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FEC9D71A-A142-4EB5-920F-170DAD90F352}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE