2016-11-04 63 views
0

我有以下類,但是我需要聲明一個字符串數組而不是[String]成員變量。語法是什麼?PowerShell類字符串語法的數組

class SomeClass{ 
    [String] $patterns; 

    SomeClass(){ 
    $this.patterns = "Maintenance Code","Page \d+ of"; 
    } 

    [Bool]SomeMethod([string]$txt){} 
} 
+0

'[System.String []' – PetSerAl

+0

謝謝,這工作 –

+0

有人照顧判斷,而不是僅僅回答。 –

回答

0

因此,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