[Edit 02/01/2012 - PowerShell added support for this in Version 2 via the following syntax:]
PS > $r = New-Object "System.Collections.Generic.List[Int]"
PS > $r.Add(10)
PS > $r.Add("Hello")
Cannot convert argument "item", with value: "Hello", for "Add" to type "System.Int32"
(...)
At line:1 char:1
+ $r.Add("Hello")
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
(Original Post)
Although the New-Object cmdlet is powerful, it doesn’t yet handle creating generic types very elegantly. For a simple parameterized type, you can use the syntax that the .Net framework uses under the hood:
