-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Import-Module $PSScriptRoot\carClass.ps1 | ||
|
||
|
||
# Using Static "new" method | ||
$redSportsCar = [car]::new("100","red") | ||
|
||
# Using New-Object. Parameters for Argument list are positional and required by the constructor. | ||
$blueSportsCar = New-Object car -ArgumentList "100", "red" | ||
|
||
# Using a HashTable. Note: requires default or parameterless constructor. | ||
$greenSportsCar = [car]@{ | ||
topSpeed = "100" | ||
colour = "green" | ||
} | ||
|
||
# Dynamic Object Type using a variable name. | ||
$type = "Car" | ||
$whiteSportsCar = New-Object -TypeName $type |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class car | ||
{ | ||
#Props | ||
[Int32] $topSpeed | ||
[string] $colour | ||
|
||
# Static Props | ||
Static [string] $UK = "Right" | ||
Static [string] $US = "Left" | ||
|
||
# Hidden Props | ||
|
||
Hidden [string] $cO2Output | ||
|
||
#paramless constructor | ||
car () | ||
{ | ||
|
||
} | ||
|
||
#constructor | ||
car ([int32]$topSpeed,[string]$colour) | ||
{ | ||
$this.topSpeed = $topSpeed | ||
$this.colour = $colour | ||
} | ||
|
||
# Method | ||
# add turbo 10% boost to top speed | ||
[String] addTurbo() | ||
{ | ||
$this.topSpeed = $this.topSpeed + (($this.topSpeed / 100)*10) | ||
|
||
return "boost added top speed is now :"+$this.topSpeed | ||
} | ||
|
||
#Static method | ||
Static [string] getTopSpeed() | ||
{ | ||
return [car]::topspeed | ||
} | ||
} |
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
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