irvnriir
irvnriir

Reputation: 826

Append content of array to Collections.Generic.List

if i try to

$g = [System.Collections.Generic.List[char[]]]@()
$g.AddRange([char[]]@('1','2'))

i get this

Cannot convert argument "collection", with value: "System.Char[]", for "AddRange" to type "System.Collections.Generic.IEnumerable`1[System.Char[]]"

Upvotes: 0

Views: 123

Answers (1)

apc
apc

Reputation: 5566

Lets break it down:

Cannot convert argument "collection"

The compiler can't convert between one type and another for the parameter called "collection"

with value: "System.Char[]"

Means you are passing a Char Array (System.Char[])

for "AddRange" 

You are passing the Char Array to the AddRange method.

 to type "System.Collections.Generic.IEnumerable`1[System.Char[]]"

AddRange is expecting an IEnumerable (e.g. List or array) of Char Arrays

So, cant convert from Char Array to an Array/List of Char Arrays

So either:

  • You are calling the wrong method and should be calling Add not AddRange
  • or the type of your collection should be Char not Char[]

Upvotes: 1

Related Questions