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

  • Home
  • SEARCH
  • 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 8367499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:10:31+00:00 2026-06-09T13:10:31+00:00

I have a base class that has an abstract method which returns a list

  • 0

I have a base class that has an abstract method which returns a list of itself.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public abstract class baseclass
    {
        public abstract List<baseclass> somemethod();        
    }
}

And a descendant that tries to override the base class’s method by returning a list of *it*self.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class childclass : baseclass
    {
        public override List<childclass> somemethod()
        {
            List<childclass> result = new List<childclass>();
            result.Add(new childclass("test"));
            return result;
        }

        public childclass(string desc)
        {
            Description = desc;
        }

        public string Description;
    }
}

But I get this error:

Error   1   'ConsoleApplication1.childclass.somemethod()':
return type must be 'System.Collections.Generic.List<ConsoleApplication1.baseclass>'
to match overridden member 'ConsoleApplication1.baseclass.somemethod()' 
C:\Users\josephst\AppData\Local\Temporary Projects\ConsoleApplication1childclass.cs 
0   42  ConsoleApplication1

What’s the best approach to have a base class return a list of itself, overriding the base class’s method that does the same thing?

  • 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-09T13:10:32+00:00Added an answer on June 9, 2026 at 1:10 pm

    Generic i s nice solution, but don’t use public abstract List<baseclass> somemethod(); it’s bad practice

    You should use non-virtual interface pattern

    public abstract class BaseClass<T>
    {
        protected abstract List<T> DoSomeMethod();
    
        public List<T> SomeMethod()
        {
            return DoSomeMethod();
        }
    }
    
    public class ChildClass : BaseClass<ChildClass>
    {
        protected override List<ChildClass> DoSomeMethod(){ ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an abstract base class Animal which has public virtual abstract method
I have a base class that has an abstract getType() method. I want subclasses
Say I have an abstract base class that has a method to generate Foo
I have a abstract base C# class with a couple of methods that has
I have a base class ReportElement which has type property: public abstract class ReportElement
I have a Base class that needs a Generic type. That can be either
I have a Generic Base Class that I want to allow one of two
I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have a abstract base class that I have many inherited classes coming off
In my game I have a base class of Loot which has methods universal

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.