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

Why does the second line below fail at runtime even though the first compiles fine?

object[] arr = new string[3]; // compiles arr[0] = 42; // ArrayTypeMismatchException at runtime