0

Can I make Implicit/Explicit conversion between two lists i.e.

List<Person> person = new List<Human>();
  • 1
    No, I'm afraid you can't. – ProgrammingLlama Apr 24 '20 at 01:21
  • Not exactly clear if you are asking if you can add implicit/explicit conversion operators to existing type (List) or trying to do conversion between list of derived classes to list of base classes... But good thing we already have answers to both. If you are asking something else - [edit] question to clarify. – Alexei Levenkov Apr 24 '20 at 01:29
  • 1
    Try it with a type that has implicit conversion already, and you'll see that you can't: `List foo = new List();` – Rufus L Apr 24 '20 at 01:31
  • 1
    You can assign a list of humans to a list of persons with an explicit cast in a select statement, though `List people = humans.Select(h => (Person)h).ToList();` (assuming such a cast is valid). – Rufus L Apr 24 '20 at 01:43

0 Answers0