Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC#covariance and contravarianceSingle-choice MCQ

Why does the second assignment fail to compile while the first succeeds?

IEnumerable<string> strings = new List<string>(); IEnumerable<object> objects = strings; // line 1 List<string> stringList = new List<string>(); List<object> objectList = stringList; // line 2