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

Intro Delegates

parent d3ee0045
No related branches found
No related tags found
No related merge requests found
...@@ -33,9 +33,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P11Mi Vererbung", "P11Mi Ve ...@@ -33,9 +33,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P11Mi Vererbung", "P11Mi Ve
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P14 GenericList", "P14 GenericList\P14 GenericList.csproj", "{4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P14 GenericList", "P14 GenericList\P14 GenericList.csproj", "{4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P15 GenericSort", "P15 GenericSort\P15 GenericSort.csproj", "{35FAC883-FC17-4B7B-BA86-93B91B3C9803}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P15 GenericSort", "P15 GenericSort\P15 GenericSort.csproj", "{35FAC883-FC17-4B7B-BA86-93B91B3C9803}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P16 GenericKeyValueList", "P16 GenericKeyValueList\P16 GenericKeyValueList.csproj", "{43F7D344-EBBF-4672-9452-AE59A1C977BF}" 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}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -111,6 +113,10 @@ Global ...@@ -111,6 +113,10 @@ Global
{43F7D344-EBBF-4672-9452-AE59A1C977BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.Build.0 = Release|Any CPU {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.Build.0 = Release|Any CPU
{8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
...@@ -99,6 +99,12 @@ namespace P14_GenericList ...@@ -99,6 +99,12 @@ namespace P14_GenericList
for (LItem? item = first; item != null; item = item.next) for (LItem? item = first; item != null; item = item.next)
yield return item.data; yield return item.data;
} }
//public IEnumerable<T?> Filter(testfunktion)
//{
// for (LItem? item = first; item != null; item = item.next)
// if (item.data[0] == "S") testfunktion(data)-->bool
// yield return item.data;
//}
public void ReversePrintList() public void ReversePrintList()
{ {
for (LItem? item = last; item != null; item = item.prev) for (LItem? item = last; item != null; item = item.prev)
......
...@@ -61,5 +61,10 @@ namespace P16_GenericKeyValueList ...@@ -61,5 +61,10 @@ namespace P16_GenericKeyValueList
for (LItem item = first; item != null; item = item.next) for (LItem item = first; item != null; item = item.next)
yield return (item.Key, item.Value); yield return (item.Key, item.Value);
} }
public void Print()
{
for(LItem item = first;item != null; item = item.next)
Console.WriteLine($"{item.Key}: {item.Value}");
}
} }
} }
namespace P16_GenericKeyValueList namespace P16_GenericKeyValueList
{ {
internal class Program class Termin
{
public string was;
public string wer;
public Termin(string was, string wer) { this.was = was; this.wer = wer; }
public override string ToString() => $"Termin: {was} mit {wer}";
}
class ComplexKey : IComparable<ComplexKey>
{
public int Wert1 { get; set; }
public string Wert2 { get; set; }
public ComplexKey(int Wert1, string Wert2) { this.Wert1 = Wert1; this.Wert2 = Wert2; }
public int CompareTo(ComplexKey other)
{
int diff = Wert1.CompareTo(other.Wert1);
if (diff != 0)
return diff;
return Wert2.CompareTo(other.Wert2);
}
}
class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
...@@ -13,6 +34,69 @@ ...@@ -13,6 +34,69 @@
foreach (var item in tel) { foreach (var item in tel) {
Console.WriteLine( $"{item.Item1}: {item.Item2}"); Console.WriteLine( $"{item.Item1}: {item.Item2}");
} }
}
KeyValueList<string, int> kvListe = new KeyValueList<string, int>();
kvListe["Wienkop"] = 1614;
kvListe["Otsa"] = 1855;
Console.WriteLine($"Telefonnummer von Wienkop: {kvListe["Wienkop"]}");
Console.WriteLine("-----------");
kvListe.Print();
Console.WriteLine("-----------");
kvListe["Otsa"] = 9999;
kvListe.Print();
Console.WriteLine("-----------");
KeyValueList<string, Termin> termine = new KeyValueList<string, Termin>();
termine["Wienkop"] = new Termin("IT-Proj", "Digitale Visitenkarte");
termine.Print();
//foreach (var item in termine)
//{
// Console.WriteLine(item.val);
//}
List<Termin> termineMi = new List<Termin>();
termineMi.Add(new Termin("08:00 Prog2-Vorlesung", "Gruppe-Wienkop"));
termineMi.Add(new Termin("09:45 Dig Bildbearbeitung", "MA-MIN"));
List<Termin> termineDi = new List<Termin>();
termineDi.Add(new Termin("08:00 Prog2-Übung", "Gruppe-Wienkop"));
termineDi.Add(new Termin("09:45 Prog2-Vorlesung", "Gruppe-Wienkop"));
termineDi.Add(new Termin("11:30 Mitarbeiterbesprechung", "Jobbörse"));
KeyValueList<string, List<Termin>> terminverwaltung = new KeyValueList<string, List<Termin>>();
terminverwaltung["02.06.2020"] = termineDi;
terminverwaltung["03.06.2020"] = termineMi;
terminverwaltung["02.06.2020"]?.Add(new Termin("11:30 Teams", "BayernMINT"));
// Pfannkuchen, Zutaten(Mehl, Milch, Eier), Zubereitung (Schritt1, Schritt2, ...)
KeyValueList<string, (List<string>, List<string>)> rezepte = new KeyValueList<string, (List<string>, List<string>)>();
List<string> zutaten = new List<string>();
zutaten.Add("Mehl");
zutaten.Add("Milch");
zutaten.Add("Eier");
List<string> zubereitung = new List<string>();
zubereitung.Add("Eier in Schüssel schlagen");
zubereitung.Add("mit Mehl und Milch verrühren");
rezepte["Pfannkuchen"] = (zutaten, zubereitung);
List<string> zutaten2;
List<string> zubereitung2;
(zutaten2, zubereitung2) = rezepte["Pfannkuchen"];
Console.WriteLine("Zutaten: ");
foreach (var item in zutaten2)
{
Console.WriteLine(item);
}
Console.WriteLine("Zubereitung:");
foreach (var item in zubereitung2)
{
Console.WriteLine(item);
}
}
} }
} }
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>P17_Intro_Delegates</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
namespace P17_Intro_Delegates
{
internal class Program
{
static double Square(double x) => x * x;
static double Mal2(double x) => 2 * x;
delegate double ZulaessigeFunktionen(double x);
static void Wertetabelle(double von, double bis,
double schrittweite, ZulaessigeFunktionen fkt)
{
for (double x = von; x <= bis ; x+= schrittweite)
Console.WriteLine( $"{x:f8} | {fkt(x):f8}");
Console.WriteLine( "------------");
}
static void Main(string[] args)
{
Wertetabelle(0, 5, 1, Square);
Wertetabelle(0, 5, 1, Mal2);
Wertetabelle(0, 5, 1, Math.Sin);
Wertetabelle(0, 5, 1, delegate (double xxx) { return xxx + 1; });
Wertetabelle(0, 5, 1, y => y + 2);
ZulaessigeFunktionen meineFunktRef;
meineFunktRef = Square;
Console.WriteLine(meineFunktRef(10));
meineFunktRef = z => z + 10;
Console.WriteLine(meineFunktRef(10));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment