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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:55:08+00:00 2026-06-05T23:55:08+00:00

This issue has been on/off bugging me and I’ve written 4 wrappers now. I’m

  • 0

This issue has been on/off bugging me and I’ve written 4 wrappers now. I’m certain I’m doing it wrong and need to figure out where my understanding is branching off.

Let’s say I’m using the Rectangle class to represent bars of metal. (this works better then animals)

So say the base class is called “Bar”.

private class Bar
{
   internal Rectangle Area;
}

So. Now we make a rectangle, say 300 units by 10 units.

private Bar CreateBar()
{
    Bar1 = new Bar1();
    Bar1.Area = new Rectangle(new Point(0,0), new Size(300,10));
    return Bar1;
}

Fantastic, so we have a base bar.

Now let’s say we want to make this bar have a material – say steel. So. . .

private class SteelBar : Bar
{
    string Material;
}

So if I did this. . .

private SteelBar CreateSteelBar()
{
    SteelBar SteelB = new SteelB();
    Bar B = CreateBar();
    SteelB = B;
    SteelB.Material = "Steel";
    return SteelB;
}

From what I get from this if I call CreateSteelBar, it creates a steelbar that calls CreateBar. So I end up with a steel bar with a 300 by 10 rectangle, and a nulled or empty string for material. Then I set the material to steel.

When I try something similar in my program, it keeps telling I cannot implicitly create a higher up class from a lower down class. I would have figured this is why inheritance exists considering all the inherits from animal examples I see, but am hoping someone can clear me up.

Also, I’m certain I could call SteelBar = CreateBar(); but I did it the long way here.

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

    Instead of having a method (CreateBar), you’d use a constructor:

    public Bar()
    {
        this.Area = new Rectangle(new Point(0,0), new Size(300,10));
    }
    

    Then, in SteelBar, you’d call the base class constructor:

    public SteelBar()
    {
        this.Material = "Steel";
    }
    

    The base class constructor will occur first, so your area will already be setup. You can be explicit about this, though, and show it in your code:

    public SteelBar()
        : base()
    {
        this.Material = "Steel";
    }
    

    However, this is typically only used if you want to have a specific constructor that takes arguments.

    For details, see Constructors in the C# programming guide.

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

Sidebar

Related Questions

This issue has been bugging me for the past several days. I've been working
Have been stuck with this issue for a few days now, and really need,
This has been a long term issue I need your collective genius to solve.
I know this issue has been touched on here but I have not found
so I am having this issue that has been driving me crazy for hours,
This has been a rather problematic issue on numerous occasions. We have alot of
My development team of four people has been facing this issue for some time
I've been having this issue for a while now and was never really able
This has been bothering me for a while now: Could not load file or
I've had an issue with Visual Studio that has been bugging me for some

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.