Commit d591607b authored by Uwe Wienkop's avatar Uwe Wienkop

2020-07-08 Mi

parent 40a25eb1
......@@ -77,8 +77,8 @@ namespace _06InterfaceStack
{
static void Main(string[] args)
{
//IStack<string> stack1 = new ArrayStack<string>();
IStack<string> stack1 = new ListStack<string>();
IStack<string> stack1 = new ArrayStack<string>();
//IStack<string> stack1 = new ListStack<string>();
//IStack<string> stack1 = new IStack<string>();
// Nicht zulässig, da IStack<> eine abstrakte Klasse ist!
stack1.Push("Anton");
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_12Interfaces</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _12Interfaces
{
interface IStackable
{
void Push(int z);
int Pop();
}
//abstract class Stack
//{
// abstract public void Push(int z);
// abstract public int Pop();
//}
class Stack : IStackable
{
int[] speicher = new int[10];
int count = 0;
public int Pop()=> speicher[--count];
public void Push(int z)
{
speicher[count++] = z;
}
public int Count { get => count; }
}
class Program
{
static void Main(string[] args)
{
Stack stapel = new Stack();
stapel.Push(10);
stapel.Push(20);
stapel.Push(30);
Console.WriteLine(stapel.Pop());
Console.WriteLine(stapel.Pop());
Console.WriteLine(stapel.Count); //-- geht nicht, da stat.Typ von stapel IStack ist
Console.WriteLine((stapel as Stack).Count);
}
}
}
\ No newline at end of file
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"12Interfaces/1.0.0": {
"runtime": {
"12Interfaces.dll": {}
}
}
}
},
"libraries": {
"12Interfaces/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\\12Interfaces\\12Interfaces.csproj": {}
},
"projects": {
"C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\12Interfaces.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\12Interfaces.csproj",
"projectName": "12Interfaces",
"projectPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\12Interfaces.csproj",
"packagesPath": "C:\\Users\\wienkop\\.nuget\\packages\\",
"outputPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\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,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.301\\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("12Interfaces")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("12Interfaces")]
[assembly: System.Reflection.AssemblyTitleAttribute("12Interfaces")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Von der MSBuild WriteCodeFragment-Klasse generiert.
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\bin\Debug\netcoreapp3.1\12Interfaces.exe
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\bin\Debug\netcoreapp3.1\12Interfaces.deps.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\bin\Debug\netcoreapp3.1\12Interfaces.runtimeconfig.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\bin\Debug\netcoreapp3.1\12Interfaces.runtimeconfig.dev.json
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\bin\Debug\netcoreapp3.1\12Interfaces.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\bin\Debug\netcoreapp3.1\12Interfaces.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\obj\Debug\netcoreapp3.1\12Interfaces.AssemblyInfoInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\obj\Debug\netcoreapp3.1\12Interfaces.AssemblyInfo.cs
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\obj\Debug\netcoreapp3.1\12Interfaces.csproj.CoreCompileInputs.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\obj\Debug\netcoreapp3.1\12Interfaces.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\obj\Debug\netcoreapp3.1\12Interfaces.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12Interfaces\obj\Debug\netcoreapp3.1\12Interfaces.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\\12Interfaces\\12Interfaces.csproj",
"projectName": "12Interfaces",
"projectPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\12Interfaces.csproj",
"packagesPath": "C:\\Users\\wienkop\\.nuget\\packages\\",
"outputPath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\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,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\3.1.301\\RuntimeIdentifierGraph.json"
}
}
}
}
\ No newline at end of file
{
"version": 2,
"dgSpecHash": "ZwTv7qOuW3hJUkys8ho3nbAcqsZTMVjgqwwjOumRyOqYelzUfCtK5XtInr/b9BQXXyEvViTv8Bfzr+6nQaRnOg==",
"success": true,
"projectFilePath": "C:\\Users\\wienkop\\source\\repos\\prog2-ss2020-wienkop\\12Interfaces\\12Interfaces.csproj",
"expectedPackageFiles": [],
"logs": []
}
\ No newline at end of file
using System;
using System.Security.Cryptography;
namespace _12ToString
{
class Person
{
string name, vorname;
public string name, vorname;
public Person(string name, string vorname)
{
this.name = name; this.vorname = vorname;
......@@ -18,16 +19,46 @@ namespace _12ToString
}
class SpecPerson : Person
{
public SpecPerson(string name, string vorname) : base(name, vorname) { }
int alter;
public SpecPerson(string name, string vorname, int alter) : base(name, vorname) { this.alter = alter; }
public override string ToString() => $"(SpecPerson) {base.ToString()}";
public void TueEtwas() { }
//public static explicit operator SpecPerson(Person p)
//{
// return new SpecPerson(p.name, p.vorname, 20);
//}
}
class SuperSpecPerson : SpecPerson
{
public SuperSpecPerson(string name, string vorname, int alter) : base(name, vorname, alter) { }
public override string ToString() => $"(SpecSpecPerson) {base.ToString()}";
}
class Program
{
static void Main(string[] args)
{
SpecPerson p1 = new SpecPerson("Meier", "Anton"); // p1: statischer Typ: SpecPerson, dynTyp: SpecPerson
Person p2 = p1; // p1: stat.Typ: Person, dyn.Typ: SpecPerson
// Jede SpecPerson ist eine Person!
SpecPerson p1 = new SpecPerson("Meier", "Anton", 10); // Objekt wird bei #100.000 angelegt
p1.TueEtwas();
// p1: statischer Typ: SpecPerson, dynTyp: SpecPerson
// Statischer Typ bestimmt die zur Verfügung stehenden Methoden
// Dynamischer Typ bestimmt, welche Ausprägung (override) einer geerbten Methode genommen wird
Person p2 = new SpecPerson("Meier", "Anton", 10);
//Person p2 = p1; // p1: stat.Typ: Person, dyn.Typ: SpecPerson
// Jede SpecPerson ist eine Person!
Person p3 = new Person("Huber","Berta");
// p2.TueEtwas(); -- geht nicht, da die Klasse Person keine TueEtwas() Methode enthält
(p2 as SpecPerson).TueEtwas();
SpecPerson pp = (p3 as SpecPerson); // Konvertierung geht hier nicht, da p3 NUR eine Person (und keine
// SpecPerson ist; as liefert hier null zurück
pp?.TueEtwas();
Console.WriteLine(p1);
Console.WriteLine(p2);
}
......
......@@ -10,3 +10,4 @@ C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12ToString\obj\Debug\netcorea
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12ToString\obj\Debug\netcoreapp3.1\12ToString.dll
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12ToString\obj\Debug\netcoreapp3.1\12ToString.pdb
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12ToString\obj\Debug\netcoreapp3.1\12ToString.genruntimeconfig.cache
C:\Users\wienkop\source\repos\prog2-ss2020-wienkop\12ToString\obj\Debug\netcoreapp3.1\12ToString.csprojAssemblyReference.cache
......@@ -142,7 +142,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11 UebgDiTransformator", "1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12Delegateaufrufausbreitung", "12Delegateaufrufausbreitung\12Delegateaufrufausbreitung.csproj", "{3235FAA2-2391-4A94-A574-57261E1AAB1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12ToString", "12ToString\12ToString.csproj", "{B54DE051-ED45-4A3B-9D57-907DD7BB7C81}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12ToString", "12ToString\12ToString.csproj", "{B54DE051-ED45-4A3B-9D57-907DD7BB7C81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12Interfaces", "12Interfaces\12Interfaces.csproj", "{A4CE9D31-9638-47BF-AA34-D87E9FE3C8F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -422,6 +424,10 @@ Global
{B54DE051-ED45-4A3B-9D57-907DD7BB7C81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B54DE051-ED45-4A3B-9D57-907DD7BB7C81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B54DE051-ED45-4A3B-9D57-907DD7BB7C81}.Release|Any CPU.Build.0 = Release|Any CPU
{A4CE9D31-9638-47BF-AA34-D87E9FE3C8F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4CE9D31-9638-47BF-AA34-D87E9FE3C8F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4CE9D31-9638-47BF-AA34-D87E9FE3C8F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4CE9D31-9638-47BF-AA34-D87E9FE3C8F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
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