473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

global instances

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

Nov 16 '05 #1
3 1730
Jax
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
Nov 16 '05 #2
Hi,

If you want that a class will have only one instance then you should use
the Singleton pattern, for a great explanation of how to implement it take a
look at Skeet's article:
www.yoda.arachsys.com/csharp/singleton.html
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"garak" <fp*******@gmx-dot-de.no-spam.invalid> wrote in message
news:40********@127.0.0.1...
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

Nov 16 '05 #3
Thank you very much, the singleton patterns are the solution for me
:))

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
3
by: CsProviders | last post by:
i am a newbie to .net programming, i am having problem with global data and form instanciation. My questions are How do i maintain global data in windows forms applications? How do i navigate from...
24
by: onnodb | last post by:
Hi all, Currently, I'm working on an Access XP database app that uses two global objects in its code. These two objects are instances of "controller classes". For example, one of them manages...
8
by: yinglcs | last post by:
Hi, I read this article about global variable in c: http://www.phim.unibe.ch/comp_doc/c_manual/C/SYNTAX/glo_int_vars.html But I have a few questions 1. how can I declare the global variable...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.