global instances

  • Thread starter Thread starter garak
  • Start date Start date
G

garak

Hi,

I have a project with 5 Classes. PMAIN ist my main class, where I make
instances of all the other classes.
The Class ENVIRONMEN, ROOM and CHARACTER are instanciated only one
time !!!
Many methods in all these classes need to be some instances of the
other classes as prameters.
e.g. myRoom.Draw (ENVIRONMENT myEnvironment, CHARACTER myCharacter)

Is there a possibility to access the one instances of the classes
without passing them via parameter to the
method.
What I have in mind is something like a global instance which I make
in the PMAIN class and which I can
access in all other classes like mentioned in the small example above.


Thanks for any ideas

Frank
 
You want a static instance
E.
using System

namespace ConsoleApplication

/// <summary
/// Summary description for Class1
/// </summary
class Class

public static int someInt
/// <summary
/// The main entry point for the application
/// </summary
[STAThread
static void Main(string[] args

someInt = 25
SomeMethod()
/
// TODO: Add code to start application her
/

private static void SomeMethod(

Console.WriteLine(someInt.ToString())




The static int is available from anywhere in the class
If your going to use a class instance remember to initialize it before using it

hope that help

jax
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top