1

Why is this not legitimate code?

 public interface IExcelExport<in T>
{
    byte[] ExportSheetsToExcel(IDictionary<string, IEnumerable<T>> data, bool formatDateColumns = true);
}

Which gives this error.

Invalid variance: The type parameter 'T' must be invariantly valid on 'IExcelExport<T>.ExportSheetsToExcel(IDictionary<string, List<T>>, bool)'. 'T' is contravariant.

Why can't i use a contravariant type as a dictionary value? Any potential workarounds?

MrBliz
  • 5,830
  • 15
  • 57
  • 81

0 Answers0