C# class in folder and needs to call on class in another folder

c++, class, directory, reference, xna

I have a folder named StartUp, it holds the beginning classes and are loaded up first in the program. I want to access another folder named OverAll, it holds classes that will be used over the whole game. I want to take from OverAll a class named Mouses, and transfer it over the any other class in StartUp.

EDIT: 10:00 12/7/2013

This is the Files and Folders, lets take for example that Mouses.cs has an public int thing = 1; and I want it to move to TitleScreen.cs, what do I wright to allow TitleScreen.cs to view/edit that int?

I can access all classes in Game1.cs by calling on there folder then the class (Ex. OverAll.Mouses.ect = 1;) and vic-versa.

Files and folders


using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Audio;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.GamerServices;using Microsoft.Xna.Framework.Graphics;using Microsoft.Xna.Framework.Input;namespace Lover__Regret{    class Mouses    {        public int thing = 1;    }}


using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.Graphics;using Microsoft.Xna.Framework.Input;namespace Love__Regret.StartUp{    class TitleScreen    {        public static void Update(GameTime gameTime)        {        //Want to call thing here        }    }}

Best Solution

Well, the thing field in Mouses is not a static field. That means you need to have an instance reference to Mouses inside TitleScreen in order to be able to access it.

You said that in Game1.cs you already have references to instances. So, what I suggest is to do the following:

  1. The Update method in TitleScreen should not be static. You need to Update a specific TitleScreen instance. So remove the static keyword.
  2. Create a constructor for TitleScreen that takes a instance of Mouses and a field to store that instance:

    private Mouses _mouseHandler;

    public TitleScreen(Mouses mouseHandler){ _mouseHandler = mouseHandler;}

  3. Then, in the Update method call something like this:

    Console.WriteLine(_mouseHandler.thing); // or whatever you want to do with fields from Mouses

  4. Now, when you construct TitleScreen in Game1.cs, create it like this, passing a Mouses instance:

    // create the mouses instance (e.g.: Mouses mouses = new Mouses())
    TitleScreen screen = new TitleScreen(mouses);

Most of programming is not done via static classes/methods (that would be procedural-ish programming). You instead need to create instances of your classes.