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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:08:01+00:00 2026-06-06T12:08:01+00:00

I have a collection class like this: public class SomeDataCollection : List<ISomeData> { //

  • 0

I have a collection class like this:

public class SomeDataCollection : List<ISomeData>
{
    // some method ...
}

but I can’t do this:

SomeDataCollection someDatas = new List<ISomeData>();

Cannot implicitly convert type List<ISomeData> to SomeDataCollection. An explicit conversion exists (are you missing a cast?)

so I try to create an implicit coverter inside SomeDataCollection collection class:

public static implicit operator SomeDataCollection(List<ISomeData> l)
{
    var someDatas = new SomeDataCollection();
    someDatas.AddRange(l);
    return someDatas;
}

but it said that I can’t create such converter:

SomeDataCollection.implicit operator SomeDataCollection(List<ISomeData>): user-defined conversions to or from a base class are not allowed

And when I cast it like this:

SomeDataCollection someDatas = (SomeDataCollection)new List<ISomeData>();

it throws an error that said:

System.InvalidCastException: Unable to cast object of type List<ISomeData> to type SomeDataCollection.

How can I do this:

SomeDataCollection someDatas = new List<ISomeData>();

without getting an error? Please help. Thanks in advance.

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

    A new List<ISomeData>(); is still just a List<ISomeData>. It isn’t a SomeDataCollection. The point of subclassing is that the subclass could have extra state etc, but an object (once created) never changes type.

    You are not allowed to create operators between types in the same hierarchy, as that would subvert the usual and expected casting behaviour.

    You could use simply:

    var data = new SomeDataCollection();
    

    However I should add that frankly it is rarely useful to subclass List<T>. Not least, it doesn’t expose any useful virtual methods, so you can’t tweak the behaviour. I would honestly just use a List<ISomeData> (and remove SomeDataCollection completely) unless I have a clear and demonstrable purpose for it. And then: I might either encapsulate the list, or inherit from Collection<T>.

    You could always just add the method as an extension method?

    public static class Utils {
        public static void SomeMethod(this IList<ISomeData> list) {
          ...
        }
    }
    

    then:

    var list = new List<ISomeData>();
    ...
    list.SomeMethod();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of entities with an any-association, like this: public class CreatedLog
I have built myself a generic collection class which is defined like this. public
I have a class like this : public class SubClass <T> extends SuperClass<Collection<T>>{ public
I have a class like this: class someClass { public static function getBy($method,$value) {
I have a class that has a sub collection. Something like this: public class
I have something like this public class Reminders() { public List<SelectListItem> Reminder { get;
I have a wrapped list that looks like this: [JsonObject(MemberSerialization.Fields)] public class OrderManager :
I have a class that I would like to use in a scala.collection.mutable.PriorityQueue, but
I have a collection of country objects that look like this: class country {
Assuming I have an Entity Framework 4.2 class like this: class Company { public

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.