Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2006, 10:58 PM
Registered User
 
Join Date: Sep 2006
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
 
Old September 11th, 2006, 04:45 PM
Authorized User
 
Join Date: Jul 2004
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





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





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