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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:34:49+00:00 2026-06-09T23:34:49+00:00

I have an abstract class which defines a number of classes which can be

  • 0

I have an abstract class which defines a number of classes which can be voted on and then sorted. Since these classes all share the properties by which they are sorted, I would like to include a method at the abstract level which will let me sort them by these properties, but I’m running in to trouble with ‘not assignable to parameter’ errors.

How should I handle the following:

internal abstract class ESCO
{
    public double HotScore { get; set; }
    public double VoteTotal { get; set; }
    public DateTime Created { get; set; }

    protected static List<ESCO> SortedItems(List<ESCO> escoList, ListSortType sortType)
    {
        switch (sortType)
        {
            case ListSortType.Hot:
                escoList.Sort(delegate(ESCO p1, ESCO p2) { return p2.HotScore.CompareTo(p1.HotScore); });
                return escoList;
            case ListSortType.Top:
                escoList.Sort(delegate(ESCO p1, ESCO p2) { return p2.VoteTotal.CompareTo(p1.VoteTotal); });
                return escoList;
            case ListSortType.Recent:
                escoList.Sort(delegate(ESCO p1, ESCO p2) { return p2.Created.CompareTo(p1.Created); });
                return escoList;
            default:
                throw new ArgumentOutOfRangeException("sortType");
        }
    }
    private SPUser GetCreatorFromListValue(SPListItem item)
    {
        var user = new SPFieldUserValue(SPContext.Current.Web, (string)item["Author"]);
        return user.User;
    }
    private static VoteMeta InformationForThisVote(List<Vote> votes, int itemId)
    {} // There are more methods not being shown with code to show why I used
       // abstract instead of something else
}

Trying to implement as such:

class Post : ESCO
{
    public string Summary { get; set; } // Properties in addition to abstract
    public Uri Link { get; set; } // Properties in addition to abstract 

    public static List<Post> Posts(SPListItemCollection items, ListSortType sortType, List<Vote> votes)
    {
        var returnlist = new List<Post>();
        for (int i = 0; i < items.Count; i++) { returnlist.Add(new Post(items[i], votes)); }
        return SortedItems(returnlist, sortType);
    }

I am totally open to “You’re doing it all wrong”.

  • 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-09T23:34:50+00:00Added an answer on June 9, 2026 at 11:34 pm

    I can’t reproduce the same error message, but I think the error you are getting is because

    return SortedItems(returnlist, sortType);
    

    is attempting to return a list of the abstract base class. Try changing that to

    return SortedItems(returnlist, sortType).Cast<Post>().ToList();
    

    You’ll need to include the System.Linq namespace if you did not already.

    FYI, the error I get (in a simplified test case) is

    Cannot implicitly convert type System.Collections.Generic.List<MyNamespace.ESCO>' to 'System.Collections.Generic.List<MyNamespace.Post>'

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

Sidebar

Related Questions

I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend
I have two classes (MVC view model) which inherits from one abstract base class.
I have an abstract immutable base class that defines enforces child classes to be
Possible Duplicate: Enum “Inheritance” I have a number of classes which extend an abstract
Suppose I have an abstract base class, that just defines a container on which
I have this parent abstract class which defines an Apache logger static object. Something
I have an abstract class which contains method for setting header text. It looks
In my console application have an abstract Factory class Listener which contains code for
I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have one parent class, which is abstract class for now, for four different

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.