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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:22:01+00:00 2026-05-14T08:22:01+00:00

I have a list: private readonly IList<IList<GameObjectController>> removeTargets; private readonly IList<IList<GameObjectController>> addTargets; PickUp inherits

  • 0

I have a list:

private readonly IList<IList<GameObjectController>> removeTargets;
private readonly IList<IList<GameObjectController>> addTargets;

PickUp inherits from GameObjectController. But when I try this:

public IList<PickUp> Inventory

// ... 

gameObjectManager.MoveFromListToWorld(this, user.Model.Inventory);

// ...

    // This queues everything up to be removed, until ProcessMoves...() is called
    public void MoveFromWorldToList(GameObjectController removedFromWorld, IList<GameObjectController> addTarget)
    {
        toBeRemoved.Add(removedFromWorld);
        addTargets.Add(addTarget);
    }

// ...

    /// <summary>
    /// Removes all the GameObjects on which removal is requested from the world.
    /// </summary>
    public void ProcessMovesFromListToWorld()
    {
        for (int i = 0; i < toBeAdded.Count; i++)
        {
            GameObjectController moved = toBeAdded[i];
            addGameObjectToWorld(moved);

            if (removeTargets[i] != null)
            {
                removeTargets[i].Remove(moved);
            }
        }
        toBeAdded.Clear();
        removeTargets.Clear();
    }

I get a compiler error:

cannot convert from
‘System.Collections.Generic.IList<PickUp>’
to
‘System.Collections.Generic.IList<GameObjectController>’

Why does this occur? Shouldn’t this be fine, since PickUp is a subclass of GameObjectController? Do I need something like Java’s Map<E extends GameObjectController>?

Earlier, I was having a similar problem, where I was trying to implicitly cast inventory from an IList to an ICollection. Is this the same problem?

  • 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-14T08:22:01+00:00Added an answer on May 14, 2026 at 8:22 am

    See my other answer here:
    How to return an IQueryable<Something> as an IQueryable<ISomething>

    Short version:

    Remember that IList<PickUp> and IList<GameObjectController> are two (and only two) completely different classes in the type system. The only inheritance relationship they have comes from the System.Collections branch of the inheritance tree; there is none at all on the GameObjectController branch of the inheritance tree. You might as well try to cast an IList<double> to an IList<ArgumentNullException>.

    What you can do instead is call the Cast<T>() extension method that is available for IEnumerable<T>.

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

Sidebar

Related Questions

Here's what I have private readonly Dictionary<Type, List<object>> _cache; public IList<T> Get<T> (Expression<Func<T, bool>>
I have a List<MyClass> The class is like this: private class MyClass { public
I have a private readonly list of LinkLabel s ( IList<LinkLabel> ). I later
Say I have a class public class TimestampedTrackId { private readonly int trackId; private
I have the following domain model: public class Name { private readonly string fullName;
So I have something like the following in Java: private List<SomeType>variable; // ....variable is
I have an array list of objects in my application. private static ArrayList<Player> userList=new
I have the following method in my code: private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate)
Currently, I have a JList listen to list selection listener. private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt)
I have list of files which contain particular patterns, but those files have been

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.