Chapter 4
Activities
- It’s all about memory. As we mentioned, the stack has limited space, and value-type objects are held in the stack. Therefore, it makes sense to conserve memory as much as possible while being transparent to the human writing the code.
[Int64]
type objects take up twice as much space on the stack as[Int32]
type objects. MyString
has been told to take the contents ofMyVariable
, the integer42
, and treat it as a string. We can subsequently put an integer inMyString
, because we didn’t constrain it in any way when we created it.Doing it the other way around, with
[string]$MyOtherString
, constrainsMyOtherString
to only be able to contain strings.
Exercises
- There’s a space in there – spaces aren’t allowed. If we really must use a space in the variable name, then we must enclose it in curly braces –
{My Variable}
, which is arguably more work than using a variable name that doesn’t include a...