Home > front end >  Append content of array to Collections.Generic.List
Append content of array to Collections.Generic.List

Time:09-02

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[]]"

CodePudding user response:

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[]
  •  Tags:  
  • .net
  • Related