p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2005 (http://p2p.wrox.com/forumdisplay.php?f=138)
-   -   C# classes working for multiple forms w/ reseting (http://p2p.wrox.com/showthread.php?t=47318)

Nathan Fleming September 2nd, 2006 10:58 PM

C# classes working for multiple forms w/ reseting
I am trying to use a class with all of my [u]windows forms </u>in Visual C#.. I keep having to do

MyStats Stat1 = new MyStats();
and it starts the constructor all over...
I somehow need to just set up one Stat in the memory,
Someone mentioned Statics to me and others said there are no Globals in C#...
Honestly I have no clue I just started programming C# three days ago...


coderforrent.com September 11th, 2006 04:45 PM

a static class is the answer you are looking for. In a C# process, a static member of a class can be access from anywhere within the process. In your example:

public MyStats
  public static MyStats Instance = new MyStats();
  private MyStats()

That is a singleton design pattern. This means that this class can only have one instance and that instance can only be accessed from the MyStats.Instance member.

Hope this helps!

Get A Computer Job!

Computer Parts & Accessories

All times are GMT -4. The time now is 04:17 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.