Skip to content

Instantly share code, notes, and snippets.

@d630
Last active July 13, 2018 02:14
Show Gist options
  • Save d630/a86c42d5fdc554edc3043fdc8bc0fc26 to your computer and use it in GitHub Desktop.
Save d630/a86c42d5fdc554edc3043fdc8bc0fc26 to your computer and use it in GitHub Desktop.
Tag 6: Properties
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();
}
}
}
@d630
Copy link
Author

d630 commented Jun 12, 2018

Statt getter/setter-NetBeans-Pattern-Zeug also

@d630
Copy link
Author

d630 commented Jun 12, 2018

Siehe: https://csharp-station.com/Tutorial/CSharp/Lesson10

Es gibt aber noch weiteres, => etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment