diff --git a/OOP2024_AMP.sln b/OOP2024_AMP.sln index 47296da3d417bce8177b4b09f83bbccc4445a10a..f3ae1abd30d4390a6104af0a6b86c45b9deafcc6 100644 --- a/OOP2024_AMP.sln +++ b/OOP2024_AMP.sln @@ -37,7 +37,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P15 GenericSort", "P15 Gene EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P16 GenericKeyValueList", "P16 GenericKeyValueList\P16 GenericKeyValueList.csproj", "{43F7D344-EBBF-4672-9452-AE59A1C977BF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P17 Intro Delegates", "P17 Intro Delegates\P17 Intro Delegates.csproj", "{8E449A0E-B181-4E03-9BF5-732A32CF7A02}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P17 Intro Delegates", "P17 Intro Delegates\P17 Intro Delegates.csproj", "{8E449A0E-B181-4E03-9BF5-732A32CF7A02}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P18 Delegate Uebg", "P18 Delegate Uebg\P18 Delegate Uebg.csproj", "{0E2DADFD-9A74-499C-8B0F-8D5F05A0C890}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P19 WPF_Demo", "P19 WPF_Demo\P19 WPF_Demo.csproj", "{5E98294F-B48D-4D2D-B26E-43B36AEAD46F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P20 Liste mit Delegate", "P20 Liste mit Delegate\P20 Liste mit Delegate.csproj", "{FF28F272-A827-4234-B95C-947C69D26349}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -117,6 +123,18 @@ Global {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Release|Any CPU.Build.0 = Release|Any CPU + {0E2DADFD-9A74-499C-8B0F-8D5F05A0C890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E2DADFD-9A74-499C-8B0F-8D5F05A0C890}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E2DADFD-9A74-499C-8B0F-8D5F05A0C890}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E2DADFD-9A74-499C-8B0F-8D5F05A0C890}.Release|Any CPU.Build.0 = Release|Any CPU + {5E98294F-B48D-4D2D-B26E-43B36AEAD46F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E98294F-B48D-4D2D-B26E-43B36AEAD46F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E98294F-B48D-4D2D-B26E-43B36AEAD46F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E98294F-B48D-4D2D-B26E-43B36AEAD46F}.Release|Any CPU.Build.0 = Release|Any CPU + {FF28F272-A827-4234-B95C-947C69D26349}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF28F272-A827-4234-B95C-947C69D26349}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF28F272-A827-4234-B95C-947C69D26349}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF28F272-A827-4234-B95C-947C69D26349}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/P17 Intro Delegates/Program.cs b/P17 Intro Delegates/Program.cs index 15680f86e54cac83eb93cc41386358869d3ec640..4a907d6dc3d12ee6461696c403e351421a2c7d8d 100644 --- a/P17 Intro Delegates/Program.cs +++ b/P17 Intro Delegates/Program.cs @@ -10,7 +10,7 @@ double schrittweite, ZulaessigeFunktionen fkt) { for (double x = von; x <= bis ; x+= schrittweite) - Console.WriteLine( $"{x:f8} | {fkt(x):f8}"); + Console.WriteLine( $"{x,8:f2} | {fkt(x),8:f2}"); Console.WriteLine( "------------"); } static void Main(string[] args) @@ -24,7 +24,7 @@ ZulaessigeFunktionen meineFunktRef; meineFunktRef = Square; Console.WriteLine(meineFunktRef(10)); - meineFunktRef = z => z + 10; + meineFunktRef += z => z + 10; Console.WriteLine(meineFunktRef(10)); } } diff --git a/P18 Delegate Uebg/P18 Delegate Uebg.csproj b/P18 Delegate Uebg/P18 Delegate Uebg.csproj new file mode 100644 index 0000000000000000000000000000000000000000..08ad19aaa7d8609e4b451fc0297a6e6c6094c0c1 --- /dev/null +++ b/P18 Delegate Uebg/P18 Delegate Uebg.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>P18_Delegate_Uebg</RootNamespace> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/P18 Delegate Uebg/Program.cs b/P18 Delegate Uebg/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..509b06c59b77b691634544f18eb84b59bbba2f70 --- /dev/null +++ b/P18 Delegate Uebg/Program.cs @@ -0,0 +1,47 @@ +namespace P18_Delegate_Uebg +{ + // 1) Erstellen Sie eine Methode PrintAll, die ein Feld eines + // beliebigen Typs entgegennimmt und alle Feldelemente + // in einer Zeile ausdruckt. + // + // 2) Erstellen Sie eine Methode ForAll, die eine Methode und + // ein Feld eines beliebigen Typs entgegennimmt (gerne auch + // per params) und die Methode auf alle Feldelemente anwendet + // und das geänderte Feld zurückliefert. + // ForAll(x=>x*x, 1,2,3,4,5) + // + // 3) Erstellen Sie eine Methode Select, die wiederum eine + // Methode und ein Feld eines beliebigen Typs entgegennimmt + // und ein Ergebnisfeld zurückliefert, welches nur diejenigen + // Feldelemente enthält, die den Kriterien der Filtermethode + // entsprechen. + // Select(x=>x%2==0, 1,2,3,4,5) + internal class Program + { + delegate T ChangeFn<T>(T x); + delegate bool FilterFn<T>(T x); + + static int[] ForAll(ChangeFn<int> fn, params int[] array) + { + for (int i = 0; i < array.Length; i++) + { + array[i] = fn(array[i]); + } + return array; + } + //static T[] ForAll<T>(ChangeFn<T> fn, params T[] array) + //{ + + //} + static T[] Select<T>(FilterFn<T> fn, T[] array) + { + List<T> list = new List<T>(); + list.Add(array[0]); + return list.ToArray(); + } + static void Main(string[] args) + { + ForAll(x => x * x, 1, 2, 3, 4, 5); + } + } +} diff --git a/P19 WPF_Demo/App.xaml b/P19 WPF_Demo/App.xaml new file mode 100644 index 0000000000000000000000000000000000000000..1da2d33e9191fda33bfcf22cc859056ba84accbc --- /dev/null +++ b/P19 WPF_Demo/App.xaml @@ -0,0 +1,9 @@ +<Application x:Class="P19_WPF_Demo.App" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:P19_WPF_Demo" + StartupUri="MainWindow.xaml"> + <Application.Resources> + + </Application.Resources> +</Application> diff --git a/P19 WPF_Demo/App.xaml.cs b/P19 WPF_Demo/App.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..f60f0fe41c797f2884f5af98b40baa8a02e10cb0 --- /dev/null +++ b/P19 WPF_Demo/App.xaml.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace P19_WPF_Demo +{ + /// <summary> + /// Interaction logic for App.xaml + /// </summary> + public partial class App : Application + { + } + +} diff --git a/P19 WPF_Demo/AssemblyInfo.cs b/P19 WPF_Demo/AssemblyInfo.cs new file mode 100644 index 0000000000000000000000000000000000000000..b0ec827578bab22ee9959849b4a2e11ecfc228c0 --- /dev/null +++ b/P19 WPF_Demo/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/P19 WPF_Demo/MainWindow.xaml b/P19 WPF_Demo/MainWindow.xaml new file mode 100644 index 0000000000000000000000000000000000000000..69c4e68111de815c45e9ac16bae45aa0ca8f06a5 --- /dev/null +++ b/P19 WPF_Demo/MainWindow.xaml @@ -0,0 +1,28 @@ +<Window x:Class="P19_WPF_Demo.MainWindow" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:P19_WPF_Demo" + mc:Ignorable="d" + Title="MainWindow" Height="450" Width="800"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="77*"/> + <ColumnDefinition Width="723*"/> + </Grid.ColumnDefinitions> + <TextBox x:Name="meineTextbox" Grid.Column="1" HorizontalAlignment="Left" Margin="178,114,0,0" TextWrapping="Wrap" Text="Mein Text" VerticalAlignment="Top" Width="271" Height="103" MouseEnter="MausFaehrtHinein" MouseLeave="MausVerlaesstTb"/> + <Button Grid.Column="1" Content="Start!" HorizontalAlignment="Left" Margin="361,282,0,0" VerticalAlignment="Top" Click="Button_Click"/> + <Label x:Name="meinLabel" Grid.Column="1" Content="Label" HorizontalAlignment="Left" Margin="494,274,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="193"> + <Label.RenderTransform> + <TransformGroup> + <ScaleTransform/> + <SkewTransform/> + <RotateTransform Angle="1.17"/> + <TranslateTransform/> + </TransformGroup> + </Label.RenderTransform> + </Label> + + </Grid> +</Window> diff --git a/P19 WPF_Demo/MainWindow.xaml.cs b/P19 WPF_Demo/MainWindow.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..05e839ca9fa2e76cd426411b6fbe76d6c84c7d1e --- /dev/null +++ b/P19 WPF_Demo/MainWindow.xaml.cs @@ -0,0 +1,47 @@ +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace P19_WPF_Demo +{ + /// <summary> + /// Interaction logic for MainWindow.xaml + /// </summary> + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void MausFaehrtHinein(object sender, MouseEventArgs e) + { + if (sender is TextBox tb) + { + var defaultBrush = tb.Background; + tb.Background = new SolidColorBrush(Colors.Red); + tb.Tag = defaultBrush; + } + } + + private void MausVerlaesstTb(object sender, MouseEventArgs e) + { + if (sender is TextBox tb && tb.Tag is Brush defaultbrush) + { + tb.Background = defaultbrush; + } + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + meinLabel.Content = meineTextbox.Text; + } + } +} \ No newline at end of file diff --git a/P19 WPF_Demo/P19 WPF_Demo.csproj b/P19 WPF_Demo/P19 WPF_Demo.csproj new file mode 100644 index 0000000000000000000000000000000000000000..8b8b68e134086a6b149d5d9aa96de992e79c0e27 --- /dev/null +++ b/P19 WPF_Demo/P19 WPF_Demo.csproj @@ -0,0 +1,12 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>WinExe</OutputType> + <TargetFramework>net8.0-windows</TargetFramework> + <RootNamespace>P19_WPF_Demo</RootNamespace> + <Nullable>enable</Nullable> + <ImplicitUsings>enable</ImplicitUsings> + <UseWPF>true</UseWPF> + </PropertyGroup> + +</Project> diff --git a/P20 Liste mit Delegate/P20 Liste mit Delegate.csproj b/P20 Liste mit Delegate/P20 Liste mit Delegate.csproj new file mode 100644 index 0000000000000000000000000000000000000000..d38a625bbb4fa9cb2dcdf7905311dc92c3c08757 --- /dev/null +++ b/P20 Liste mit Delegate/P20 Liste mit Delegate.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>P20_Liste_mit_Delegate</RootNamespace> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/P20 Liste mit Delegate/Program.cs b/P20 Liste mit Delegate/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..6c088a0a4e7dcc8c40de421e673a52b0cf61eb35 --- /dev/null +++ b/P20 Liste mit Delegate/Program.cs @@ -0,0 +1,60 @@ + +namespace P20_Liste_mit_Delegate +{ + class Liste<T> + { + class LItem + { + public T data; + public LItem next = null; + public LItem(T data) { this.data = data; } + } + LItem first = null, last = null; + public void Add(params T[] dataarray) + { + foreach (var data in dataarray) + { + LItem item = new LItem(data); + if (last == null) + { + first = last = item; + } + else + { + last = last.next = item; + } + + } + } + public delegate bool meinTest<T>(T s); + internal IEnumerable<T> AllPers(meinTest<T> test) + { + for (LItem item = first; item != null; item = item.next) + { + if (test(item.data)==true) + yield return item.data; + } + } + } + internal class Program + { + static void Main(string[] args) + { + Liste<string> pers = new Liste<string>(); + pers.Add("Anton"); + pers.Add("Berta", "Claudia", "Dieter", "Egon"); + //foreach (var item in pers.AllPers(s => s.Contains("er"))) + foreach (var item in pers.AllPers(s => s[^1] == 'n')) + { + Console.WriteLine(item); + } + + Liste<int> il = new(); + il.Add(1,2,3,4,5,6,7,8,9); + foreach (var item in il.AllPers(x => x%2==0)) + { + Console.WriteLine(item); + } + } + } +}