File tree Expand file tree Collapse file tree 6 files changed +37
-35
lines changed Expand file tree Collapse file tree 6 files changed +37
-35
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,14 @@ class CLS {
7
7
[int ] $num
8
8
[string ] $txt
9
9
10
+ static [int ] $accumulator = 42
11
+
10
12
#
11
13
# The class's constructor:
12
14
#
13
15
CLS($n , $t ) {
14
16
$this.num = $n
15
17
$this.txt = $t
16
-
17
18
}
18
19
19
20
#
@@ -24,7 +25,7 @@ class CLS {
24
25
}
25
26
26
27
#
27
- # A member methot that doesn't return
28
+ # A member method that doesn't return
28
29
# a value. It's «return type» can be
29
30
# explicitely specified as void:
30
31
#
@@ -35,38 +36,8 @@ class CLS {
35
36
#
36
37
# A static method
37
38
#
38
- static [Int ] add($x , $y ) {
39
- return $x + $y
39
+ static [Int ] add($x ) {
40
+ [CLS ]::accumulator += $x
41
+ return [CLS ]::accumulator
40
42
}
41
-
42
43
}
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
-
Original file line number Diff line number Diff line change
1
+ . ./ CLS.ps1
2
+ . ./ create- instance.ps1
3
+ . ./ call- methods.ps1
4
+ . ./ call- static - method.ps1
5
+ . ./ type.ps1
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ #
2
+ # Invoke a static method
3
+ #
4
+ [CLS ]::add(57 )
5
+ #
6
+ # 99
Original file line number Diff line number Diff line change
1
+ $obj = [CLS ]::new(42 , ' hello world' )
Original file line number Diff line number Diff line change
1
+ $obj.GetType ().FullName
2
+ #
3
+ # CLS
4
+
5
+ $obj.GetType ().BaseType.FullName
6
+ #
7
+ # System.Object
8
+
You can’t perform that action at this time.
0 commit comments