Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 2nd, 2006, 10:58 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...

I
  #2 (permalink)  
Old September 11th, 2006, 04:45 PM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

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!

www.CoderForRent.com
Get A Computer Job!

www.ComputersComplete.com
Computer Parts & Accessories
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
working with multiple forms jill2new Visual Basic 2005 Basics 1 March 1st, 2007 06:48 PM
multiple CSS classes different way dk6607 CSS Cascading Style Sheets 3 December 6th, 2006 08:23 AM
counter keeps reseting FlashMan Classic ASP Professional 7 September 30th, 2004 12:56 PM
Multiple classes smilodon ASP.NET 1.0 and 1.1 Basics 8 June 9th, 2004 12:03 PM



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


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