Commit dc78d7fc authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

2020-06-10 Mi

parent d79c6e4d
......@@ -115,16 +115,15 @@ namespace _06GenericList
// an der gespeicherten Pos. weitergemacht.
}
}
public delegate bool MyFilter<V>(V daten);
public IEnumerable<T> Filter(MyFilter<T> myTest) // string => bool, x => x.Contains("er")
public delegate bool MyFilter1(T daten); // Typpar. T wird vom äußeren Class<T> genommen
public delegate bool MyFilter2<V>(V daten); // Typpar. V zunächst noch offen und wird dann
// bei der Verwendung in Filter auf MyFilter2<T> gesetzt ~ Predicate<T>
public IEnumerable<T> Filter(Predicate<T> myTest) // string => bool, x => x.Contains("er")
{
for (Element item = anf; item != null; item = item.next)
{
if (myTest(item.daten))
yield return item.daten; // Merken dieser Ausführungsposition
// UND Zurückliefern von item.name
// Beim nächsten Aufruf von GetEnumerator() wird
// an der gespeicherten Pos. weitergemacht.
if (myTest(item.daten)) // if (item.daten.Contains(pattern))
yield return item.daten;
}
}
......
......@@ -4,7 +4,7 @@ namespace _06GenericList
{
class Person : IComparable<Person>
{
string name, vorname;
public string name, vorname;
public Person(string name, string vorname)
{
this.name = name;
......@@ -19,16 +19,28 @@ namespace _06GenericList
}
class Program
{
static bool IstGerade(uint z)
{
return z % 2 == 0;
}
private static string pattern;
static bool Namenstest(Person x)
{
return x.name.Contains(pattern) &&
(x.vorname.Contains("e") || x.vorname.Contains("E"));
}
static void Main(string[] args)
{
Liste<int> il = new Liste<int>();
Liste<uint> il = new Liste<uint>();
il.AddEnd(10);
il.AddEnd(20);
il.AddEnd(23);
il.AddEnd(21);
il.AddEnd(35);
il.AddEnd(40);
foreach (var item in il.Filter(x => x%2==0))
//foreach (var item in il.Filter(x => x % 2 == 0))
foreach (var item in il.Filter(IstGerade)) // T => bool
{
Console.WriteLine(item);
}
......@@ -45,15 +57,25 @@ namespace _06GenericList
Console.WriteLine(item);
}
Console.WriteLine("*****************");
sl.Print();
//sl.Print();
Liste<Person> pl = new Liste<Person>();
pl.AddSorted(new Person("Meier", "Emil"));
pl.AddSorted(new Person("Schmitt", "Anton"));
pl.Print();
pl.AddSorted(new Person("Huber", "Dieter"));
pl.AddSorted(new Person("Müller", "Berta"));
//foreach (var item in pl.Filter(x => x.name.Contains("er")&&(x.vorname.Contains("e")||x.vorname.Contains("E"))))
//foreach (var item in pl.Filter(x => x.name.Length<6 && x.vorname.Contains("er")))
pattern = "er";
foreach (var item in pl.Filter(Namenstest))
{
Console.WriteLine(item);
}
//pl.Print();
Liste<Liste<Person>> pll = new Liste<Liste<Person>>();
pll.AddSorted(pl);
//Liste<Liste<Person>> pll = new Liste<Liste<Person>>();
//pll.AddSorted(pl);
}
}
......
......@@ -10,3 +10,4 @@ C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06GenericList\obj\Debug\netco
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06GenericList\obj\Debug\netcoreapp3.1\06GenericList.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06GenericList\obj\Debug\netcoreapp3.1\06GenericList.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06GenericList\obj\Debug\netcoreapp3.1\06GenericList.genruntimeconfig.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\06GenericList\obj\Debug\netcoreapp3.1\06GenericList.csprojAssemblyReference.cache
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_08_DelegateAnwendungen</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _08_DelegateAnwendungen
{
class Program
{
delegate T MeineFkt<T>(T x);
//delegate bool MeinTest<T>(T x);
static T[] ApplyAll<T>(MeineFkt<T> fkt, params T[] werte)
{
T[] erg = new T[werte.Length];
for (int i = 0; i < werte.Length; i++)
{
erg[i] = fkt(werte[i]);
Console.Write (erg[i]); Console.Write(" ");
}
Console.WriteLine();
return erg;
}
static int Quadrieren(int x) => x * x;
static void Main(string[] args)
{
ApplyAll(x => (int) (x * 1.02), 10, 30, 40, 50, 60, 70, 80, 100);
ApplyAll(x => x + 1, 10, 30, 40, 50, 60, 70, 80, 100);
ApplyAll(x => x * 2, 10, 30, 40, 50, 60, 70, 80, 100);
ApplyAll(Quadrieren, 10, 30, 40, 50, 60, 70, 80, 100);
Console.WriteLine("----------");
string[] namen = { "Anton", "Berta", "Claudia", "Emil", "Dieter" };
ApplyAll(x => x.ToUpper(), namen);
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"08 DelegateAnwendungen/1.0.0": {
"runtime": {
"08 DelegateAnwendungen.dll": {}
}
}
}
},
"libraries": {
"08 DelegateAnwendungen/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment