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 7023081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:39:56+00:00 2026-05-27T23:39:56+00:00

There are the following 4 objects declared: abstract class AConfigAction {} abstract class APlugin<ConfigActionType>

  • 0

There are the following 4 objects declared:

abstract class AConfigAction {}

abstract class APlugin<ConfigActionType> where ConfigActionType :AConfigAction {}

class AppExecuteConfigAction : AConfigAction {}

class AppExecutePlugin : APlugin<AppExecuteConfigAction>{}
  • All classes are public. Bodies have been removed for simplicity.

Why this fails to be converted?

_plugins = new List<APlugin<AConfigAction>>();
_plugins.Add(new AppExecutePlugin());  <--- Error

cannot convert from ‘AppExecutePlugin’ to ‘APlugin’


Full error message:

Error 1 The best overloaded method match for ‘System.Collections.Generic.List>.Add(EnvironmentSwitcher.Model.ConfigAction.APlugin)’ has some invalid arguments R:\projects\EnvironmentSwitcher\EnvironmentSwitcher\View\ConfigurationActionManagerForm.cs 35

Error 2 Argument ‘1’: cannot convert from ‘EnvironmentSwitcher.Model.ConfigAction.AppExecute.AppExecutePlugin’ to ‘EnvironmentSwitcher.Model.ConfigAction.APlugin’ R:\projects\EnvironmentSwitcher\EnvironmentSwitcher\View\ConfigurationActionManagerForm.cs 35

  • 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-05-27T23:39:57+00:00Added an answer on May 27, 2026 at 11:39 pm

    Let’s make that a bit easier to understand:

    abstract class Animal {} // was AConfigAction
    abstract class Cage<T> where T : Animal {} // was APlugIn
    class Tiger : Animal {} // was AppExecuteConfigAction
    class TigerCage : Cage<Tiger>{} // was AppExecutePlugin
    
    var cages = new List<Cage<Animal>>();    
    cages.Add(new TigerCage()); // Why is this an error?
    

    Suppose that were legal. What stops this?

    class Shark : Animal {} // some other config action
    ...
    var cages = new List<Cage<Animal>>();    
    cages.Add(new TigerCage()); 
    Cage<Animal> firstCage = cages[0]; 
    firstCage.InsertIntoCage(new Shark());
    

    firstCage is of type Cage<Animal> which implies that it can hold any kind of animal. But in fact we know that it is a tigers-only cage. You just put a shark into a tiger cage, which seems uncomfortable for both the shark and the tiger.

    Obviously that cannot be allowed. What prevents it? The only thing that prevents it is that it is illegal to put a tiger cage into a collection of animal cages in the first place. A tiger cage is not a kind of animal cage because there are things you can do with an animal cage that you cannot do with a tiger cage, namely, put a shark into it. A basic principle of object-oriented design is that subtypes can do everything their supertypes can do; a tiger cage cannot do everything an animal cage can do, so it is not a subtype.

    The more highfalutin way to say this is that generic types cannot be made to be covariant in their type arguments because doing so would violate the Liskov Substitution Principle. In C# 4, certain interfaces and delegates are covariant in their type arguments. For example, it is legal in C# 4 to put an IEnumerable<Tiger> into a List<IEnumerable<Animal>>> because there’s no way that this can be made unsafe. We can uphold the substitution principle while allowing covariance because IEnumerable<T> is an “out-only” interface. You only ever take tigers out; there’s no way to put sharks in.

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

Sidebar

Related Questions

I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
In C++, you can do the following: class base_class { public: virtual void do_something()
I've got the following classes: class A { void commonFunction() = 0; } class
Consider the following example code: class Foo { }; class Bar : public Foo
I have a image declared like the following: [Bindable] [Embed( source=assets/banana.png )] public var
assume the following class is given: class Base{ public: Base() {} Base( const Base&
I have the following scenario: I have abstract classes A and B , and
Given the following Java code: public class Test { static private class MyThread extends
Is there any difference between following two ways of creating an object. Student s1
In VB.Net is there any difference between the following three ways of initialising object

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.