Skip to content

Commit 6485f8e

Browse files
Droesel the simple class up
1 parent 556f13a commit 6485f8e

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

language/class/simple.ps1 renamed to language/class/simple/CLS.ps1

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ class CLS {
77
[int ] $num
88
[string] $txt
99

10+
static [int] $accumulator = 42
11+
1012
#
1113
# The class's constructor:
1214
#
1315
CLS($n, $t) {
1416
$this.num = $n
1517
$this.txt = $t
16-
1718
}
1819

1920
#
@@ -24,7 +25,7 @@ class CLS {
2425
}
2526

2627
#
27-
# A member methot that doesn't return
28+
# A member method that doesn't return
2829
# a value. It's «return type» can be
2930
# explicitely specified as void:
3031
#
@@ -35,38 +36,8 @@ class CLS {
3536
#
3637
# A static method
3738
#
38-
static [Int] add($x, $y) {
39-
return $x + $y
39+
static [Int] add($x) {
40+
[CLS]::accumulator += $x
41+
return [CLS]::accumulator
4042
}
41-
4243
}
43-
44-
$obj = [CLS]::new(42, 'hello world')
45-
46-
write-host "obj.num = $($obj.num), obj.txt = $($obj.txt)"
47-
#
48-
# obj.num = 42, obj.txt = hello world
49-
50-
write-host $obj.combineNumAndTxt()
51-
#
52-
# 42 - hello world
53-
54-
$obj.printMembers()
55-
#
56-
# 42 - hello world
57-
58-
#
59-
# Invoke a static method
60-
#
61-
[CLS]::add(17, 22)
62-
#
63-
# 39
64-
65-
$obj.GetType().FullName
66-
#
67-
# CLS
68-
69-
$obj.GetType().BaseType.FullName
70-
#
71-
# System.Object
72-

language/class/simple/_run.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
. ./CLS.ps1
2+
. ./create-instance.ps1
3+
. ./call-methods.ps1
4+
. ./call-static-method.ps1
5+
. ./type.ps1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
write-host "obj.num = $($obj.num), obj.txt = $($obj.txt)"
2+
#
3+
# obj.num = 42, obj.txt = hello world
4+
5+
write-host $obj.combineNumAndTxt()
6+
#
7+
# 42 - hello world
8+
9+
$obj.printMembers()
10+
#
11+
# 42 - hello world
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Invoke a static method
3+
#
4+
[CLS]::add(57)
5+
#
6+
# 99
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$obj = [CLS]::new(42, 'hello world')

language/class/simple/type.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$obj.GetType().FullName
2+
#
3+
# CLS
4+
5+
$obj.GetType().BaseType.FullName
6+
#
7+
# System.Object
8+

0 commit comments

Comments
 (0)