fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. object[] objects = null;
  8. int[] ints = null;
  9. string[] strings = null;
  10.  
  11. // this works because arrays are covariant
  12. objects = strings;
  13. // this doesn't work because we're mixing reference types with value types
  14. objects = ints;
  15. }
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(14,13): error CS0029: Cannot implicitly convert type `int[]' to `object[]'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty