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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:52:02+00:00 2026-06-12T05:52:02+00:00

Hey I have an abstract generic type BList<TElement> where TElement : Career . Career

  • 0

Hey I have an abstract generic type BList<TElement> where TElement : Career. Career is abstract type too.

Given a type T, how do I test if it is a BList type? And how can I cast to the base class? I tried (BList<Career>)object but the compiler was upset. Apparently I can’t write BList<Career> because Career is abstract.

  • 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-12T05:52:04+00:00Added an answer on June 12, 2026 at 5:52 am

    There’s a bit of ambiguity with your question, so I’ll attempt to answer some of the things i think you may be asking…

    If you want to check if an instance T is a BList you can just use is:

    if (someInstance is BList<Career>)
    {
    ...
    }
    

    If you want to see if a generic type parameter is a BList<Career> you can use typeof:

    if (typeof(T) == typeof(BList<Career>)
    {
    ...
    }
    

    But, if you are just wanting to see if it’s any BList<>, you can use reflection:

    var t = typeof(T);  // or someInstance.GetType() if you have an instance
    
    if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(BList<>))
    {
        ...
    }
    

    Now, as far as how do you cast a BList<TElement> to a BList<Career>? You can’t safely.

    This has nothing to do with Career being abstract, it has to do with the fact that BList<Career> does not inherit from BList<TElement> even though Career inherits from TElement.

    Consider this:

    public class Animal { }
    
    public class Dog : Animal { }
    
    public class Cat : Animal { }
    

    Given those, ask yoruself why does this not work:

    List<Animal> animals = new List<Cat>();
    

    See the problem? If we allow you to cast a List<Cat> to a List<Animal>, then all of the sudden the Add() method will support Animal instead of Cat, which means you could do this:

    animals.Add(new Dog());
    

    Clearly, there is no way we should be able to add a Dog to a List<Cat>. This is why you can’t use a List<Cat> as a List<Animal> even though Cat inherits from Animal.

    Similar case here.

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

Sidebar

Related Questions

Hey I have an abstract class named Partition which is a functor, and its
Hey we have a library class (lib/Mixpanel) that calls delayed job as follows: class
Hey I have this test back ground worker which seems to get stuck on
hey I have a small problem with my rake class CreateEvents < ActiveRecord::Migration def
Possible Duplicate: How do I clone a generic list in C#? hey i have
Hey I have small problem but I can't fix it :( I use mysql
Hey I have this configuration in my web.config <log4net> <appender name=LogFileAppender type=log4net.Appender.FileAppender> <param name=File
Hey i have any idea how i can format long time to Minutes:Seconds:Miliseconds for
Hey i have this div that shows as a popup: <div class=popup> </div> Then
Hey i have been looking around and i cant find a way to get

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.