global variable 
Author Message
 global variable

hii..
is it C# support global variable?
Thank


Tue, 17 May 2005 16:31:16 GMT  
 global variable
You can create a class and define some public static members.

Jos

Quote:
> hii..
> is it c# support global variable?
> Thank



Tue, 17 May 2005 00:59:54 GMT  
 global variable
joe,

Quote:
> is it c# support global variable?

C# is an object-oriented programming language.  You can use
"globally-visible" classes to provide the functionality that you require.  A
good example is the "Math" class found in the .Net Framework.  Look at the
"PI" member to see how it implements this "global" constant (which is not a
variable, but is probably what you are thinking of).

Regards,

Randy



Tue, 17 May 2005 01:13:38 GMT  
 global variable
using System;

namespace ConsoleApplication4
{

 // Put this in a class-library that you're free to reference from anywhere
 public class MenuState
 {
  private bool _someMember;

  public MenuState()
  {
   _someMember=false;
  }

  public bool SomeMember
  {
   get
   {
    return _someMember;
   }

   set
   {
    _someMember=value;
   }
  }
 }

 // Put this in a class-library that you're free to reference from anywhere
 public class ContainerClass
 {
  private static MenuState menuState;

  public ContainerClass ()
  {

   // If menuState has not been initialized already, initialize it
   if(menuState==null)
    menuState = new MenuState();
  }

  public MenuState MyMenuState
  {
   get { return menuState; }
  }
 }
 /// <summary>
 /// Simple test client.
 /// </summary>
 class Class1
 {
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: Add code to start application here
   //
   PrintOnce();
   PrintAgain();
   Console.WriteLine("-------");
   PrintOnce();
   PrintAgain();
  }

  static void PrintOnce ()
  {
   ContainerClass c = new ContainerClass();
   Console.WriteLine("PrintOnce State Before:   " +
c.MyMenuState.SomeMember.ToString());
   c.MyMenuState.SomeMember = true;
   Console.WriteLine("PrintOnce State After:    " +
c.MyMenuState.SomeMember.ToString());

  }

  static void PrintAgain ()
  {
   ContainerClass c = new ContainerClass();
   Console.WriteLine("PrintAgain  State Before: " +
c.MyMenuState.SomeMember.ToString());
   c.MyMenuState.SomeMember = false;
   Console.WriteLine("PrintAgain  State After:  " +
c.MyMenuState.SomeMember.ToString());
  }
 }

Quote:
}



Tue, 17 May 2005 06:16:43 GMT  
 global variable
c# doesnt support global variable. but you can use SESSION in c# to make
it act like a global variable.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 17 May 2005 07:30:19 GMT  
 global variable

Quote:

> c# doesnt support global variable. but you can use SESSION in c# to
> make it act like a global variable.

Where in the C# spec does it mention SESSION?
--
Arild Fines


Wed, 18 May 2005 01:31:01 GMT  
 global variable



Quote:

> > c# doesnt support global variable. but you can use SESSION in c# to
> > make it act like a global variable.

> Where in the C# spec does it mention SESSION?

Session is for ASP.NET apps. If you're not doing ASP.NET, you'll have
to use an alternative.

-c



Wed, 18 May 2005 04:23:15 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Global variable or not global variable

2. Uninitialized global data (was Re: Global variables)

3. static local variables vs global variables

4. Variables & Global Variables

5. global variables and external variables?

6. Why is not possible to assign a global variable to another global variable..?

7. Global variable

8. global variables

9. Regarding locks and global variables

10. Global variables

11. Declaring Global Variable accessable with in the application.

12. Problem with global variables

 

 
Powered by phpBB® Forum Software