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

2022-02-22

parent 774ede54
No related branches found
No related tags found
No related merge requests found
......@@ -2,5 +2,6 @@
"ExpandedNodes": [
""
],
"SelectedNode": "\\prog2-ss2022-wienkop.sln",
"PreviewInSolutionExplorer": false
}
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -5,7 +5,13 @@ namespace _01_IntroKlassen
class Personalausweis
{
private string name;
public int persoId { get; private set; }
// public int persoId { get; private set; }
private int _persoId;
public int persoId
{
get { return _persoId; }
private set { _persoId = value; }
}
private static int naechsteID = 1000;
// static: Dieses Datenfeld gibt es nur EINMAL für die Klasse
......@@ -17,8 +23,8 @@ namespace _01_IntroKlassen
this.persoId = naechsteID;
naechsteID++;
}
public override string ToString()
=> $"Name: {name}, Perso-Id: {persoId}";
//public override string ToString()
// => $"Name: {name}, Perso-Id: {persoId}";
public string getName() { return name; }
public int Id { get => persoId; }
public void setNaechsteId(int wert)
......@@ -30,18 +36,68 @@ namespace _01_IntroKlassen
public static int NaechsteID
{
get { return naechsteID; }
get { Console.WriteLine("get() "); return naechsteID; }
set
{
Console.WriteLine($"set({value}) ");
if (value < naechsteID)
throw new ArgumentOutOfRangeException("Die neue ID darf nicht kleiner als die Aktuelle sein!");
naechsteID = value;
}
}
}
class Buergeramt
{
private Personalausweis[] personalausweise;
private int anzPersos=0;
public Buergeramt(int anz=1000)
{
personalausweise = new Personalausweis[anz];
}
public void NeuerPersonalausweis(Personalausweis perso)
{
personalausweise[anzPersos] = perso;
anzPersos++;
}
public Personalausweis getPerso(int n)
{
return personalausweise[n];
}
public Personalausweis this [int n]
{
get => personalausweise[n];
}
public Personalausweis this[string name]
{
get
{
for (int i = 0; i < personalausweise.Length; i++)
{
if (personalausweise[i].getName() == name)
return personalausweise[i];
}
return null;
}
}
}
class Program
{
int mal2(int x) => x * 2;
static void Main(string[] args)
{
Buergeramt nuernberg = new Buergeramt(2000);
Buergeramt fuerth = new Buergeramt();
nuernberg.NeuerPersonalausweis(new Personalausweis("Anton"));
fuerth.NeuerPersonalausweis(new Personalausweis("Berta"));
Console.WriteLine(nuernberg.getPerso(0));
Console.WriteLine(nuernberg[0]);
Console.WriteLine(nuernberg["Anton"]);
}
static void Main2(string[] args)
{
Personalausweis.NaechsteID = 10000;
......@@ -54,7 +110,7 @@ namespace _01_IntroKlassen
int x = anton.Id;
//anton.Id = 444;
Personalausweis.NaechsteID = 20000;
Personalausweis.NaechsteID ++;
Personalausweis claudia = new Personalausweis("Claudia");
Console.WriteLine(claudia);
}
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment