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

Indexer + Operatorüberladung

parent dc799add
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P02 Methoden", "P02 Methode ...@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P02 Methoden", "P02 Methode
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P03 Klassen", "P03 Klassen\P03 Klassen.csproj", "{E0E52007-EEDB-4075-9371-909D9E435F61}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P03 Klassen", "P03 Klassen\P03 Klassen.csproj", "{E0E52007-EEDB-4075-9371-909D9E435F61}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P04 Brueche", "..\P04 Brueche\P04 Brueche.csproj", "{09DFCE5C-70A6-42AA-88E8-AB643EE5E790}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -33,6 +35,10 @@ Global ...@@ -33,6 +35,10 @@ Global
{E0E52007-EEDB-4075-9371-909D9E435F61}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0E52007-EEDB-4075-9371-909D9E435F61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0E52007-EEDB-4075-9371-909D9E435F61}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0E52007-EEDB-4075-9371-909D9E435F61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0E52007-EEDB-4075-9371-909D9E435F61}.Release|Any CPU.Build.0 = Release|Any CPU {E0E52007-EEDB-4075-9371-909D9E435F61}.Release|Any CPU.Build.0 = Release|Any CPU
{09DFCE5C-70A6-42AA-88E8-AB643EE5E790}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09DFCE5C-70A6-42AA-88E8-AB643EE5E790}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09DFCE5C-70A6-42AA-88E8-AB643EE5E790}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09DFCE5C-70A6-42AA-88E8-AB643EE5E790}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace P03_Klassen
{
class Buergeramt
{
int maxPersonalausweise;
int naechstePersoPos = 0; // nicht-static, da unterschiedliche Städte
Perso[] persos;
public Buergeramt(int maxPersos )
{
maxPersonalausweise = maxPersos;
persos = new Perso[ maxPersonalausweise ];
}
public Perso NeuerPersonalausweis(string name, int alter)
{
Perso neuerPerso = new Perso(name, alter);
persos[naechstePersoPos] = neuerPerso;
naechstePersoPos++;
// Test, ob Feldüberlauf ...
return neuerPerso;
}
public Perso this[int index]
{
get
{
if (index >= 0 && index < naechstePersoPos)
return persos[index];
else
throw new IndexOutOfRangeException("Ungültiger Index");
}
// ggf. auch set oder private set
}
// public string this[int index] geht nicht, da
// der Returntyp nicht beim Überladen berücksichtigt wird
public Perso this[string name]
{
get
{
for (int index=0;index < maxPersonalausweise; index++ )
if (persos[index]?.Name == name)
return persos[index];
return null;
}
}
}
}
...@@ -19,7 +19,7 @@ namespace P03_Klassen ...@@ -19,7 +19,7 @@ namespace P03_Klassen
naechstePersId = value; naechstePersId = value;
} }
} }
readonly string Name; public string Name { get; private set; }
public int Alter public int Alter
{ {
get => xyz01233; get => xyz01233;
......
...@@ -13,7 +13,12 @@ ...@@ -13,7 +13,12 @@
anton.Ausgabe(); anton.Ausgabe();
//anton.NaechstePersId = 2000; //anton.NaechstePersId = 2000;
Perso berta = new Perso("Berta", 25); Perso berta = new Perso("Berta", 25);
Buergeramt Nbg = new Buergeramt(10);
Nbg.NeuerPersonalausweis("Meier", 15);
Nbg.NeuerPersonalausweis("Müller", 27);
Console.WriteLine(Nbg["Meier"]);
Console.WriteLine(Nbg[1]);
} }
} }
} }
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