Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to initialize a Generic.List PowerShell

$
0
0

This is a very simple question but I spent 2 hours Googling not a single one works. 

$MyInList = New-Object System.Collections.Generic.List[string] $MyInlist.Add("sdf", "sdfsdf"); $MyInlist.Addrange(("sdf", "sdfsdf")); $MyInlist{"sdf", "sdfsdf"} $MyInlist.Add["sdf", "sdfsdf"]

$MyInlist

for($a=0; $a -le $MyInlist.Count; $a++){

   Write-Output $MyInlist[$a]
}


I have tried all possible combination suggested by Google and mine own but none work. To display the content I have $MyInlist all by itself and the for loop they display nothing.

I dont know what I am doing wrong but both the initialize

and to display the contents nothing works. Please suggest a fix.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>