我有以下类,但是我需要声明一个字符串数组而不是[String]成员变量。语法是什么?
class SomeClass{
[String] $patterns;
SomeClass(){
$this.patterns = "Maintenance Code","Page \d+ of";
}
[Bool]SomeMethod([string]$txt){}
}
答案 0 :(得分:1)
因为PetSerAl说[System.String []]但是[String []]就好了。
在帮助about_arrays中也提到过。
To create a strongly typed array, that is, an array that can contain only
values of a particular type, cast the variable as an array type, such
as string[], long[], or int32[]. To cast an array, precede the variable
name with an array type enclosed in brackets. For example, to create a
32-bit integer array named $ia containing four integers (1500, 2230, 3350,
and 4000), type:
[int32[]]$ia = 1500,2230,3350,4000