What C # function name allows you to implicitly treat List <ChildClass> as a list <ParentClass>

This is relevant for the technical discussion in which I participate.

+4
source share
2 answers

You say general covariance - but that does not apply to List<T> , which is invariant.

This only applies to IEnumerable<T> :

 IEnumerable<ChildClass> children = new List<ChildClass>(); IEnumerable<ParentClass> parents = children; 
+14
source
+1
source

Source: https://habr.com/ru/post/1383896/


All Articles