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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:18:37+00:00 2026-05-23T17:18:37+00:00

Is there a way of putting a static method in an abstract class that

  • 0

Is there a way of putting a static method in an abstract class that can return the derived type?

Does a static method even know what type it is even being called from in C#?

For example, a base class could be

public abstract class MyBase
{
    public static IEnumerable<TDerivedType> LoadAll()
    {
        //functionality here
    }
}

Then if MyDerivedType inherits MyBase, I’d like to be able to call MyDerivedType.LoadAll()

Nothing too important – I’m currently using a generic static method and calling MyBase.LoadAll<MyDerivedType>(), which works fine but it doesn’t look quite as ‘pretty’ as this would be.

  • 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-23T17:18:37+00:00Added an answer on May 23, 2026 at 5:18 pm

    Static members aren’t inherited, so the static method has to be told in some way what the derived type is. Your solution is one way. Another is the following:

    public abstract class MyBase<T> where T : MyBase<T> {
        public static IEnumerable<T> LoadAll() { }
    }
    

    Then:

    class Derived : MyBase<Derived> { }
    
    var all = MyBase<Derived>.LoadAll();
    

    That said, I think there is something wrong with your model. MyBase represents something in your domain (of which they are more specific derived types) AND it knows how to load all of those objects? That’s two responsibilities, and that ain’t cool yo.

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

Sidebar

Related Questions

Is there way that I can read the file from remote server using fopen
in python there is way to declare def 's without putting it in class.
Is there a simple way of putting source code into a repository and then
Is there any alternate way to create stored procedure without putting all query in
I'm pretty sure there is no way, but i'm putting this out there for
is there way thats i can preselect an item when the page loads or
Look, I know static classes can't inherit or implement. The question is what the
Is there a way to #import a class from a string in Objective-C at
When I concat($name, $surname) , is there a way of putting a space in
When I concat($name, $surname) , is there a way of putting a space in

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.