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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:36+00:00 2026-05-23T16:06:36+00:00

I’ve got a base Class ScenBase and a derived class ScenC. I have a

  • 0

I’ve got a base Class ScenBase and a derived class ScenC. I have a class HexC derived form the base class Hex. I also have a class UnitC derived from the base class Unit. I can set an array of Hex to point to an array of HexC, but the compiler won’t let me set a List of Unit to point to a list of UnitC:

// The Core Database for the game scenario.
// Theoretically multiple secenarios can be loaded
// into memory at the same time.
[Serializable]
public class ScenC : ScenBase
{
    public bool playable { get; set; }
    public HexC[,] hexCs { get; private set; }
    public List<UnitC> unitCs { get; private set; }

    // A database for every user and AI entity.
    public List<ScenV> chViews { get; private set; }
    public List<string> characters { get; private set; }

    public ScenC(int xDimI, int yDimI) : base (xDimI, yDimI)
    {
        playable = false;
        chViews = new List<ScenV>();
        characters = new List<string>();
        characters.Add("Supreme");
        hexCs = new HexC[xDim, yDim];
        hexs = hexCs;                //this line complies fine
        newHex = (int x, int y) => new HexC(this, x,  y);
        unitCs = new List<UnitC>();

        // **This line won't compile**
        unitCs = units;
        Init();
    }
}

Here are the fields properties for the base class ScenBase:

[Serializable]
public abstract class ScenBase
{
    public Hex[,] hexs;
    public List<Unit> units { get; protected set; }
    public DateTime currGameTime { get; set; }
    public int xDim { get; set; }
    public int yDim { get; set; }
    public double scale { get; protected set; }
    protected delegate Hex NewHex(int x, int y);
    protected NewHex newHex;

    //Rest of Class not shown for simplicity
}

Why Can’t I set a List<Hex> to a List<HexC> when that follows the “is a” implicit cast rule, but I can set array to array

  • 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-23T16:06:37+00:00Added an answer on May 23, 2026 at 4:06 pm

    This is not possible.

    Had it been possible, you would have been able to add a different derived type to the list.
    For example:

    List<Car> cars = new List<Car>
    List<Vehicle> vehicles = cars;   //Error!
    vehicles.Add(new Bicycle());     //That's not a car!
    

    What you’re asking for is called covariance; it’s only possible for immutable interfaces (such as IEnumerable<T>)

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.