-2

I tried to clone a List<byte[]> without reference but I get this error when I try to run the code:

cannot convert from 'System.Collections.Generic.List<byte[]>' to 'System.Collections.Generic.IEnumerable<System.Collections.Generic.List<byte[]>>

This is the code that I wanted to run:

newList = new List<List<byte[]>>(oldList).ToArray();

Does this even work, or are there other solutions?

Tim593
  • 71
  • 5
  • I think so too : newList = (List)oldList.ToList(); – Meysam Asadi Jan 25 '21 at 08:47
  • A `List` is not a `List>`. Specifically, the [List constructor](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.-ctor?view=net-5.0#System_Collections_Generic_List_1__ctor_System_Collections_Generic_IEnumerable__0__) you're using expects an `IEnumerable`, which in this case is an `IEnumerable>` according to your code. Though I'm not sure why [`newList = oldList.ToList();`](https://stackoverflow.com/a/15330708/3181933) isn't suitable in this case. – ProgrammingLlama Jan 25 '21 at 08:52

1 Answers1

-2

Try:

newList = new List<List<byte[]>>(oldList).ToList();
raj_345
  • 7
  • 2
  • Changing `.ToArray()` to `.ToList()` doesn't magically make `oldList` an `IEnumerable>`, as would be needed for this to work at all. From the error message, `oldList` is a `List`. – ProgrammingLlama Jan 25 '21 at 08:52