Commit f6e8d337 authored by Uwe Wienkop's avatar Uwe Wienkop

2020-06-02 Di

parent 59872e26
using System;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -17,7 +18,44 @@ using System.Text;
namespace _06_UebgSaGenerics
{
class GenericStack
class GenericStack <T>
{
private class Element // Element ist eine private Hilfsklasse der Klasse StringListe
{
public T obj;
public Element next = null;
public Element(T daten) { this.obj = daten; }
public override string ToString() => obj.ToString();
}
Element anf = null, ende = null;
int anz = 0; // Sehr sinnvoll für Index-Ops
//public StringListe() { }
public void AddFirst(T daten)
{
// 1. Leere Liste
// 2. Es existiert mind. ein Element
Element neuesElement = new Element(daten); // Neues Element anlegen
anz++;
if (anf == null) // 1.Fall: Leere Liste?
anf = ende = neuesElement;
else
{
neuesElement.next = anf; // 2. Fall
anf = neuesElement;
}
}
public T GetFirst(bool removeFromStack = true)
{
if (anf == null) throw new Exception("Stapel ist leer");
T zwischen = anf.obj;
if (removeFromStack == true) anf = anf.next;
return zwischen;
}
}
}
using System;
using System.Collections.Generic;
namespace _06_UebgSaGenerics
{
......@@ -7,6 +8,7 @@ namespace _06_UebgSaGenerics
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
List<int> li = new List<int>();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_07_MethodeSplitArray</RootNamespace>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
namespace _07_MethodeSplitArray
{
class Kfz : IComparable <Kfz>
{
string kennzeichen;
public Kfz(string kennzeichen) { this.kennzeichen = kennzeichen; }
public int CompareTo(Kfz other) => kennzeichen.CompareTo(other.kennzeichen);
}
class Program
{
//static int[] SplitArray(int limit, int[] f)
static U[] SplitArray<U>(U limit, params U[] f)
where U:IComparable<U> // ~Constraint
// ~Vertrag: SplitArray kann Felder von jedem Typ bearbeiten,
// der eine CompareTo-Methode enthält
{
List<U> erg = new List<U>();
foreach (var item in f)
{
if (item.CompareTo(limit) > 0)
erg.Add( item);
}
return erg.ToArray();
}
static int MyCompareTo(string s1, string s2) // "Hallo" | "Hallo2"
{
int limit = s1.Length < s2.Length ? s1.Length : s2.Length;
for (int i = 0; i < limit; i++)
{
int dif = s1[i] - s2[i];
if (dif != 0)
return dif;
}
return s1.Length - s2.Length;
}
static void Main(string[] args)
{
int[] f1 = SplitArray(3, 1, 3, 5, 7, 9, 11);
string[] f2 = SplitArray("Claudia", "Anton","Berta","Dieter","Emil");
Kfz[] f3 = SplitArray(new Kfz("N-AB 100"),
new Kfz("N-XY 300"),new Kfz("AB-MN 200"), new Kfz("ER-S 500"));
foreach (var item in f3)
{
Console.WriteLine(item);
}
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"07 MethodeSplitArray/1.0.0": {
"runtime": {
"07 MethodeSplitArray.dll": {}
}
}
}
},
"libraries": {
"07 MethodeSplitArray/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\wienkop\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\wienkop\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
{
"format": 1,
"restore": {
"C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj": {}
},
"projects": {
"C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj",
"projectName": "07 MethodeSplitArray",
"projectPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj",
"packagesPath": "C:\\Users\\wienkop\\.nuget\\packages\\",
"outputPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\wienkop\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[3.1.2, 3.1.2]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.300\\RuntimeIdentifierGraph.json"
}
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\wienkop\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.6.0</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
\ No newline at end of file
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("07 MethodeSplitArray")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("07 MethodeSplitArray")]
[assembly: System.Reflection.AssemblyTitleAttribute("07 MethodeSplitArray")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Von der MSBuild WriteCodeFragment-Klasse generiert.
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\bin\Debug\netcoreapp3.1\07 MethodeSplitArray.exe
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\bin\Debug\netcoreapp3.1\07 MethodeSplitArray.deps.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\bin\Debug\netcoreapp3.1\07 MethodeSplitArray.runtimeconfig.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\bin\Debug\netcoreapp3.1\07 MethodeSplitArray.runtimeconfig.dev.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\bin\Debug\netcoreapp3.1\07 MethodeSplitArray.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\bin\Debug\netcoreapp3.1\07 MethodeSplitArray.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.csprojAssemblyReference.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.AssemblyInfoInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.AssemblyInfo.cs
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.csproj.CoreCompileInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\07 MethodeSplitArray\obj\Debug\netcoreapp3.1\07 MethodeSplitArray.genruntimeconfig.cache
{
"version": 3,
"targets": {
".NETCoreApp,Version=v3.1": {}
},
"libraries": {},
"projectFileDependencyGroups": {
".NETCoreApp,Version=v3.1": []
},
"packageFolders": {
"C:\\Users\\wienkop\\.nuget\\packages\\": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj",
"projectName": "07 MethodeSplitArray",
"projectPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj",
"packagesPath": "C:\\Users\\wienkop\\.nuget\\packages\\",
"outputPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\wienkop\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.AspNetCore.App.Ref",
"version": "[3.1.2, 3.1.2]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.300\\RuntimeIdentifierGraph.json"
}
}
}
}
\ No newline at end of file
{
"version": 2,
"dgSpecHash": "Sv8/9Pkx5y/FYVWqEofst9XmPqmn8WCEYJf16vaQ28oURfgTkjs+wfahtJrz1GKZ1i5clht9DmXH7TYjQfbghQ==",
"success": true,
"projectFilePath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\07 MethodeSplitArray\\07 MethodeSplitArray.csproj",
"expectedPackageFiles": [
"C:\\Users\\wienkop\\.nuget\\packages\\microsoft.aspnetcore.app.ref\\3.1.2\\microsoft.aspnetcore.app.ref.3.1.2.nupkg.sha512"
],
"logs": []
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_07KeyValueList</RootNamespace>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace _07KeyValueList
{
class KeyValue<K, V> : IComparable<KeyValue<K, V>>
where K : IComparable<K>
{
public K key;
public V val;
public KeyValue(K key, V val) { this.key = key; this.val = val; }
public int CompareTo(KeyValue<K, V> other)
=> key.CompareTo(other.key);
public override string ToString() => $"{key}: {val}";
}
}
using System;
namespace _07KeyValueList
{
class Program
{
static void Main(string[] args)
{
Liste<KeyValue<string, int>> kvListe = new Liste<KeyValue<string, int>>();
kvListe.AddSorted(new KeyValue<string, int>("Wienkop", 1614));
kvListe.AddSorted(new KeyValue<string, int>("Otsa", 1855));
kvListe.Print();
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"07KeyValueList/1.0.0": {
"runtime": {
"07KeyValueList.dll": {}
}
}
}
},
"libraries": {
"07KeyValueList/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\wienkop\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\wienkop\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
namespace _07KeyValueList
{
class Liste<T> : IComparable<Liste<T>> where T : IComparable<T>
{
// Die Klasse Element ist nun eine *private* Klasse der Klasse StringListe
// Die Methoden von StringListe dürfen auf private Member zugreifen
// Methoden außerhalb von StringListe dürfen dies nicht!
private class Element // Element ist eine private Hilfsklasse der Klasse StringListe
{
public T daten;
public Element next = null;
public Element(T daten) { this.daten = daten; }
public override string ToString() => daten.ToString();
}
Element anf = null, ende = null;
int anz = 0; // Sehr sinnvoll für Index-Ops
//public StringListe() { }
public void AddEnd(T daten)
{
Element neuesElement = new Element(daten); // 1. Neues Element anlegen
anz++;
if (anf == null) // 2. Leere Liste?
anf = ende = neuesElement;
else
{