1

You can define a strictly-typed variable that is an Array with the following declaration: [System.Array]$VariableNameArray

You can also define a strictly-typed variable that is an Integer with the following declaration: [System.Int]$VariableNameInteger

However, is there a way to define a strictly-typed variable that is an Array of Integers (and not, for example, a scalar integer, or an array of strings)?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Keith Howard
  • 347
  • 4
  • 12
  • 3
    `[int[]] $myArray` – zett42 Dec 12 '22 at 07:19
  • 1
    Does this answer your question? [Array Types In Powershell - System.Object\[\] vs. arrays with specific types](https://stackoverflow.com/questions/42355649/array-types-in-powershell-system-object-vs-arrays-with-specific-types) – zett42 Dec 12 '22 at 11:59

1 Answers1

2

The type literal syntax for an array of a given type is TypeName[], so to type a variable to be an array of int's:

[int[]]$integerArrayVariableName = ...
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206