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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:51:47+00:00 2026-06-03T12:51:47+00:00

I have a base class that has methods that use a generic type in

  • 0

I have a base class that has methods that use a generic type in C#, I then have other classes that inherit from these, I want to specify the type in the parent class to avoid angle brackets everywhere…

Here’s a sample method from my base class class CBaseHome

public List<T> fetchAll<T>(CBaseDb db, bool includeEmpty = true) where T : CBaseTable, new()
{
    List<T> retVal = new List<T>();
    ...
    return retVal;
}

I the have a parent class that inherits from this class, (without overriding this function)

In the class that then consumes this I have the following code…

List<student> students = new limxpoDB.Home.student().fetchAll<student>(db, false);

so the Home.student class here inherits the CBaseHome class, and student inherits the CBaseTable…

I’d like to be able to say in the Home.student class that the only valid generic type for that class is student so that my consuming code looks like…

List<student> students = new limxpoDB.Home.student().fetchAll(db, false);

I realise here that the difference is minute, but I also use this library in some VB>Net code where it looks terrible…

Any ideas?

Thanks

  • 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-03T12:51:49+00:00Added an answer on June 3, 2026 at 12:51 pm

    Generic type parameters on a method cannot be imposed by a child class. So if I have:

    public class Parent {
        public List<T> GetStuff<T>() { ... }
    }
    

    I can not do:

    public class Child : Parent {
        // This is not legal, and there is no legal equivalent.
        public List<ChildStuff> GetStuff<ChildStuff>() { ... }
    }
    

    What you can do is make the parent class generic, rather than it’s method:

    public class Parent<T> {
        public List<T> GetStuff() { ... }
    }
    
    public class Child : Parent<ChildStuff> {
        // GetStuff for Child now automatically returns List<ChildStuff>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two case classes that inherit from an abstract base class. I want
I have a abstract base C# class with a couple of methods that has
I have a Base class that needs a Generic type. That can be either
I have a base class that has a private static member: class Base {
I have a page base class that has no .aspx file and so I
Suppose I have a Base class and a Child class that inherits from Base
I have an abstract base class that holds a Dictionary. I'd like inherited classes
In my game I have a base class of Loot which has methods universal
I have three models that look something like this: class Bucket < ActiveRecord::Base has_many
I have a base class that represents a database test in TestNG, and I

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.