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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:42:08+00:00 2026-06-04T11:42:08+00:00

I was reading a bit on generic variance and I don’t have a full

  • 0

I was reading a bit on generic variance and I don’t have a full understanding of it yet but I’d like to know if it makes something like the following possible?

class A<T> { }

class B { }

class C : B { }

class My1  {
    public My1(A<B> lessDerivedTemplateParameter)
    {
    }
}

class My2 : My1 {
    public My2(A<C> moreDerivedTemplateParameter)
        : base(moreDerivedTemplateParameter) // <-- compile error here, cannot convert
    {
    }
}
  • 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-04T11:42:10+00:00Added an answer on June 4, 2026 at 11:42 am

    No, because while C inherits from B, A<C> does not inherit from A<B>.

    To understand why this is the case, imagine if A<T> were instead List<T>:

    class B { }
    
    class C : B { }
    
    class D : B { }
    
    class My1  {
        public My1(List<B> lessDerivedTemplateParameter)
        {
           // This is totally legal
           lessDerivedTemplateParameter.Add(new D());
        }
    }
    
    class My2 : My1 {
        public My2(List<C> moreDerivedTemplateParameter)
            // if this were allowed, then My1 could add a D to a list of Bs
            : base(moreDerivedTemplateParameter)
        {
        }
    }
    

    Now on the other hand, this is legal:

    interface IA<out T> { 
        public T GetSome();
    }
    
    class B { }
    
    class C : B { }
    
    class D : B { }
    
    class My1  {
        public My1(IA<B> lessDerivedTemplateParameter)
        {
           // This is totally legal
           var someB = lessDerivedTemplateParameter.GetSome();
        }
    }
    
    class My2 : My1 {
        public My2(IA<C> moreDerivedTemplateParameter)
            // This is allowed, because an A<C> only *produces* C's (which are also B's)
            // so the base class (which consumes B's, and doesnt care if they are C's) 
            // can use an IA<C>
            : base(moreDerivedTemplateParameter)
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading a bit about Web Matrix, I like the simpleness of
I've been reading a bit about what metaclasses are, but I would like to
I've been reading up a bit about coffeescript's inheritance model and I have the
I have encountered a bit of a hiccup in something I'm working on. Suppose
Just doing a bit of reading up on Generics. I have written a little
I am new to Java and would like to know a bit more. I
I've been reading a bit about how programs handle command line parameters. But the
I have been reading a bit about caching in c# 3.5. Got a bit
After reading a bit on Javascript's prototypical inheritance model , I change my style
I'm reading 16-bit integers from a piece of hardware over the serial port. Using

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.