I am new in PowerShell but am familiar with .NET classes.
I am using System.Text.StringBuilder
in PowerShell script. The script is that
Function MyStringFunc([String]$line) {
$r = New-Object -TypeName "System.Collections.Generic.List``1[[System.String]]";
$sb = New-Object -TypeName "System.Text.StringBuilder";
foreach ($c in $line) {
$sb.Append($c);
$r.Add($sb.ToString());
}
return $r;
}
$line1 = "123";
$a = MyStringFunc $line1;
$a
I expected the result is
1
12
123
However the result is
Capacity MaxCapacity Length
-------- ----------- ------
16 2147483647 3
123
Did I do something wrong?