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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:54:42+00:00 2026-05-23T05:54:42+00:00

I have the following example relationship: namespace Yesod { public class Program { //

  • 0

I have the following example relationship:

namespace Yesod
{
    public class Program
    {
        //
        //
        //
        public struct Particle
        {
            public byte type;
        }

        //
        //
        //
        public class Entity<T>
        {
            public Entity<Entity<T>> Parent
            { get; private set; }

            //
            //
            //
            public Entity(Entity<Entity<T>> parent)
            {
                this.Parent = parent;
            }
        }

        //
        //
        //
        public sealed class Atom : Entity<Particle>
        {
            public Atom(Entity<Atom> parent)
                : base(parent) // Compile Error.
            { }
        }

        //
        //
        //
        public sealed class Molecule : Entity<Atom>
        {
            public Molecule()
                : base(null)
            { }
        }

        static void Main(string[] args)
        {

        }
    }
}

How would I solve the following compile error that the above produces?

  Argument 1: cannot convert from 'Yesod.Program.Entity<Yesod.Program.Atom>' to 'Yesod.Program.Entity<Yesod.Program.Entity<Yesod.Program.Particle>>'

Comment Reply #1:
Specifically, the code is trying to assign an object of type

Entity<Atom>

to an object of type

Entity<Entity<Particle>>

as Atom is implemented as

public sealed class Atom : Entity<Particle>

whereby

Entity<Atom>

is expected to breakdown into

Entity<Entity<Particle>>
  • 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-23T05:54:43+00:00Added an answer on May 23, 2026 at 5:54 am

    Although the potential solution posted by Daniel Martin would never work (as admittedly warned), the explanation on why my code would too never work is 100% accurate, and it has led me to discover that C# 4.0 solves this otherwise expected functionality using its new generic covariance & contra-variance language features.

    Below is the solution, for review:

    namespace Yesod
    {
        public class Program
        {
            //
            //
            //
            public struct Particle
            {
                public byte type;
            }
    
            // Fix with C# 4.0 using out keyword.
            //
            //
            public interface IEntity<out T>
            {
                IEntity<IEntity<T>> Parent
                { get; }
            }
    
            //
            //
            //
            public class Entity<T> : IEntity<T>
            {
                public IEntity<IEntity<T>> Parent
                { get; private set; }
    
                //
                //
                //
                public Entity(IEntity<IEntity<T>> parent)
                {
                    this.Parent = parent;
                }
            }
    
            //
            //
            //
            public sealed class Atom : Entity<Particle>
            {
                public Atom(Entity<Atom> parent)
                    : base(parent) // No more compile error.
                { }
            }
    
            //
            //
            //
            public sealed class Molecule : Entity<Atom>
            {
                public Molecule()
                    : base(null)
                { }
            }
    
            //
            //
            //
            static void Main(string[] args)
            {
                // Now this can be done.
                Molecule water = new Molecule();
                Atom H1 = new Atom(water);
                Atom O1 = new Atom(water);
                Atom O2 = new Atom(water);
            }
        }
    }
    

    Thanks Daniel Martin. I could not 1-up you due to my current rep. score. To those wondering, the above is a silly mock up aimed to highlight obvious parent-child relationships to help those understand the question. The real-world intended use will be an advanced version that will be employed in the field of computer graphics to solve the Coherent Space Partitioning problem in a well-defined and recursive manner.

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

Sidebar

Related Questions

I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have the following example code: class A(object): def __init__(self, id): self.myid = id
If I have the following domain object: public class Customer { public virtual Guid
I have 2 models with a many-to-many relationship (simplified here with books-authors example): class
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
I have tried using the obvious method as outlined in the following example but
I am a newbie to Python and have come across the following example in
Say for example I have the following string: var testString = Hello, world; And
I have a large result set assembled in a parent/child relationship. I need to
I have a many-to-many model, following the example in this great railscast My model

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.