Last active
July 13, 2018 02:14
-
-
Save d630/a86c42d5fdc554edc3043fdc8bc0fc26 to your computer and use it in GitHub Desktop.
Tag 6: Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace csharp | |
{ | |
public class Schiff | |
{ | |
public int Baujahr { get; set; } | |
public string Farbe { get; set; } | |
} | |
public class Auto | |
{ | |
private int baujahr; | |
private string farbe; | |
public Auto(int baujahr, string farbe) | |
{ | |
this.baujahr = baujahr; | |
this.farbe = farbe; | |
} | |
public int Baujahr { | |
get | |
{ | |
return this.baujahr; | |
} | |
set | |
{ | |
this.baujahr = value; | |
} | |
} | |
public string Farbe | |
{ | |
get | |
{ | |
return this.farbe; | |
} | |
set | |
{ | |
this.farbe = value; | |
} | |
} | |
} | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Auto a1 = new Auto(1995, "rot"); | |
Auto a2 = new Auto(2005, "blau"); | |
Console.WriteLine("{0}, {1}", a1.Baujahr.ToString(), a1.Farbe); | |
Console.WriteLine("{0}, {1}", a2.Baujahr.ToString(), a2.Farbe); | |
a1.Farbe = "gelb"; | |
a2.Farbe = "magenta"; | |
Console.WriteLine("{0}, {1}", a1.Baujahr.ToString(), a1.Farbe); | |
Console.WriteLine("{0}, {1}", a2.Baujahr.ToString(), a2.Farbe); | |
Schiff s1 = new Schiff(); | |
s1.Baujahr = 1911; | |
s1.Farbe = "grün"; | |
Console.WriteLine("{0}, {1}", s1.Baujahr.ToString(), s1.Farbe); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Statt getter/setter-NetBeans-Pattern-Zeug also