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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:44:56+00:00 2026-06-03T23:44:56+00:00

Might look a silly question, but can I return an instance? Example: public class

  • 0

Might look a silly question, but can I return an instance?
Example:

public class EcranJeu : AffichageJeu
{

    public EcranJeu(string choixecran)
    {
        if (choixecran == "0")
        {
            KystExtract décor = new KystExtract();
        }
        if (choixecran == "1")
        {
            KystExtraction décor = new KystExtraction();
        }
    }

    public override void  LoadContent()
    {
        décor.LoadContent(content);
    }
}

décor is said not to exist. How can I pass it to the LoadContent, Update and Draw of all the class?

  • 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-03T23:44:57+00:00Added an answer on June 3, 2026 at 11:44 pm

    The other answer was only partially correct as you found.

    Problem: You are creating an object of one of two different classes and later want to call a LoadContent(), or Draw() or Update() method on the chosen object.

    I have to assume the two classes KystExtract and KystExtraction have a common base class or share an interface. If not you will need to create/add one (e.g. KrystBase or IKryst) that defines the LoadContent() method.

    The property you store is then of the base class type/interface, so it can hold either a KystExtract object or a KystExtraction object.

    Your code will look like this (assuming you have no common base class and use an interface):

    public class EcranJeu : AffichageJeu
    {
        private IKystObject décor;  // for example
        public EcranJeu(string choixecran)
        {
            if (choixecran == "0")
            {
                décor = new KystExtract();
            }
            if (choixecran == "1")
            {
                décor = new KystExtraction();
            }
        }
    
        public override void  LoadContent()
        {
            décor.LoadContent(content);
        }
    }
    
    // Common interface for classes requiring shared behavior
    public interface IKystObject
    {
        public override void LoadContent();
        public override void Update();
        public override void Draw();
    }
    
    // Both classes implement your common interface
    public class KystExtract : IKrystObject
    {
        ... Implementation of LoadContent, Update and Draw
    }
    
    // Both classes implement your common interface
    public class KystExtraction : IKrystObject
    {
        ... Implementation of LoadContent, Update and Draw
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it might look like a silly question but here is my case
This might look like a silly question to some, but handling the different types
This might look as a stupid question. But, I have a class with some
This might look like a basic question to some of you but I expect
The question might look subjective but considering Microsoft: Owns the Xbox 360 platform Owns
I am back into c/Linux. The question might look stupid, but relevant after working
This question might look naive, but I couldn't understand this code in the ViewModelLocator.cs
I've just started programming with Java, so might appear as silly question, but I
This question might seem really silly to most of the enlightened folks here. But
This might look like a beaten question, but could not find an answer at

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.