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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:09:57+00:00 2026-06-04T04:09:57+00:00

I am trying to create a few nested classes within my main class. public

  • 0

I am trying to create a few nested classes within my main class.

public class MyPlayer : Player
{

    public bool TargetEnemy()
    {
        return true;

    }

    public class Movement
    {
        public uint aInt = 1;

        public TurnLeft()
        {

        }
    }

    public class ActionBar
    {

    }
}

I have many different classes so that I would be able to access the MyPlayer class through out the code without passing it to all them I just created a static class that holds the variable for it. I am able to access the MyPlayer->Movement using Main.Units.MyPlayer.Movement but this is not linked to the MyPlayer instance I have defined in the static class.

I want to be able to do MyPlayer->Movement->TurnLeft() for example. How would I achieve this? Thanks for your answers.

  • 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-04T04:10:00+00:00Added an answer on June 4, 2026 at 4:10 am

    You might be mistaking the concept of class nesting with class composition. In order to have a Movement instance within your Player class, you can define a private field movement and a public property Movement to access it.

    public class Player
    {        
        public bool TargetEnemy()
        {
            return true;            
        }
    
        private Movement movement = new Movement();
    
        public Movement Movement
        {
            get { return movement; }
            set { movement = value; }
        }
    }
    
    public class Movement
    {
        public uint aInt = 1;
    
        public TurnLeft()
        {
    
        }
    }
    
    public class ActionBar
    {
    
    }
    

    Then, you may create an instance of your Player class and access its contained Movement:

    Player myPlayer = new Player();
    myPlayer.Movement.TurnLeft();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an element within a ListView which displays a few TextViews
In the spirit of re-using code, I'm trying to create a few library projects.
I'm trying to create a check on a few columns in my database that
What i'm trying to create is a background worker that executes a few processes
I'm trying to create a script what permits me to select a few lines
I'm trying to learn JavaFX and maybe create a few learner games. I always
I'm just trying to create a new MySQL database with a few simple tables.
I'm trying to create a simple paypal purchase system. Going through a few tutorials,
I've got a few questions about edittext.. I'm trying to create a login screen
I have COM object with few constructors, I'm trying to create new instance and

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.