Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:57:16+00:00 2026-06-18T02:57:16+00:00

Given the following types: public interface IPrimary{ void doBattle(); } // an ISecondary is

  • 0

Given the following types:

public interface IPrimary{ void doBattle(); }

// an ISecondary "is" an IPrimary
public interface ISecondary : IPrimary {  }

// An implementation of ISecondary is also an IPrimary:
internal class SecondaryImpl : ISecondary
{
    // Required, since this is an IPrimary
    public void doBattle(){ }
}

Why can I not do this?

List<IPrimary> list = new List<ISecondary>();

This results in the following compilation error:

Argument type ‘System.Collections.Generic.List’ is not assignable to parameter type ‘System.Collections.Generic.List’

I understand the error, and I realize there are workarounds. I just do not see any clear reason why this direct conversion is disallowed. The values contained in a list of ISecondary, should after all, be (by extension) values of type of IPrimary.Why then are List<IPrimary> and List<ISecondary> being interpreted as unrelated types?

Can anyone explain clearly the reasoning for C# being designed this way?

A slightly extended example: I came across the issue when trying to do something similar to the following:

internal class Program
{
    private static void Main(string[] args)
    {
        // Instance of ISecondary, and by extention, IPrimary:
        var mySecondaryInstance = new SecondaryImpl();

        // This works as expected:
        AcceptImpl(mySecondaryInstance);

        // List of instances of ISecondary, which are also, 
        // by extention, instances of IPrimary:
        var myListOfSecondaries = new List<ISecondary> {mySecondaryInstance};

        // This, however, does not work (results in a compilation error):
        AcceptList(myListOfSecondaries);
    }

    // Note: IPrimary parameter:
    public static void AcceptImpl(IPrimary instance){  }

    // Note: List of type IPrimary:
    public static void AcceptList(List<IPrimary> list){  }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:57:18+00:00Added an answer on June 18, 2026 at 2:57 am

    Why can I not do this? List<IPrimary> list = new List<ISecondary>();

    Imagine that you had a method defined like this:

    public void PopulateList(List<IPrimary> listToPopulate)
    {
        listToPopulate.Add(new Primary());  // Primary does not implement ISecondary!
    }
    

    What would happen if you were to pass it a List<ISecondary> as a parameter?

    The error that List<ISecondary> is not assignable from List<IPrimary> is the compiler’s way of getting you out of such troubles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following interface and implementation class: public interface MyInterface { public String getSomething
Given the following types: public interface IMyClass { } public class MyClass : IMyClass
Given the following types private class MyTestDummyClassValidationDef : ValidationDef<MyTestDummyClass> { ... } public class
Given the following code: public interface IExample { ... } public abstract class BaseExample:
Given the following generic interface and implementing class: public interface IRepository<T> { // U
Given the following interfaces/classes: public interface IRequest<TResponse> { } public interface IHandler<TRequest, TResponse> where
Given the scenario... interface IBase{ void Process(int value); } abstract class Base : IBase
Given the following interface, public interface Callback<T> { <K, V> T execute(Operation<K, V> operation)
Given the following class structure: @MappedSuperclass @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public abstract class Animal {} @Entity public
I have the following interface and implementation: public interface IRepository<T> { IList<T> GetAll(); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.