The complete folder structure has been changed or updated
This commit is contained in:
30
examples/PowerShell/Klassenbeispiel mit Konstruktor.ps1
Normal file
30
examples/PowerShell/Klassenbeispiel mit Konstruktor.ps1
Normal file
@@ -0,0 +1,30 @@
|
||||
class Auto {
|
||||
[string]$Marke
|
||||
[string]$Modell
|
||||
[int] $Baujahr
|
||||
|
||||
Auto ([string]$marke, [string]$modell, [int]$baujahr) {
|
||||
$this.Marke = $marke
|
||||
$this.Modell = $modell
|
||||
$this.Baujahr = $baujahr
|
||||
}
|
||||
|
||||
[string] GetAutoInfo() {
|
||||
return "$($this.Marke) $($this.Modell) aus dem Jahr $($this.Baujahr)"
|
||||
}
|
||||
|
||||
[int] GetAutoAlter() {
|
||||
$aktuellesJahr = (Get-Date).Year
|
||||
return $aktuellesJahr - $this.Baujahr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
# aus dem gleichen Ordner:
|
||||
#. .\Auto.ps1
|
||||
|
||||
$meinAuto = [Auto]::new("Volkswagen", "Golf", 2020)
|
||||
$meinAuto.GetAutoInfo() # "Volkswagen Golf aus dem Jahr 2020"
|
||||
$meinAuto.GetAutoAlter() # z. B. 5
|
||||
|
||||
Reference in New Issue
Block a user