code i m trying is :-
$sumList1= New-Object System.Collections.Generic.List[int]
$sumList1.Add(1)
$sumList1.Add(2)
$sumList1.Add(3)
$sumList1.Add(4)
$i = $sumList1.Items[1];
write-host $i
please help me on this.
You made a typo, it is Item()
, not Items[]
: $sumList1.Item(1)
Or use normal index access: $i = $sumList1[1]
To change the value of an existing item use $sumList1[1] = 5
, if you want to add an element use the Add
method as in your sample code.