index > Visual C# General > global variable for windows application

global variable for windows application


hello,

how can i write and read a global variable for the entire application in C#?


Many Thanks,
Jassim Rahma




Jassim Rahma
Jassim Rahma
Hello Jassim

There is no concept of Global Variables in C#, you can use global variables inside the entire class but not in the entire namespace.

Solution for this problem is to create STATIC VARIABLES and use these variables anywhere in the namespace. Hope this might help



Mark the best replies as answers [ alirazashaikh.blogspot.com ]
ALI RAZA SHAIKH
You can use a class with some public static members or properties. Here is a little example, or you can take a look to the Singleton pattern.


public static class Globals
{
public static string MyString;
public static int MyInt;
public static double MyDouble;
}





** Microsoft Community Moderator ** http://born2code.net **
PJ. van de Sande
reply 3

You can use google to search for other answers

 

More Articles

• why (Object reference not set to an instance of an object)?
• Problem with Visual Studio C# Express Edition
• Clearing Cookies
• FileInfo.LastWriteTime issue: does not correctly evaluate
• scrollable datagrid
• convert image to icon
• Updating text in a ToolStripStatusLabel.
• combox.text
• How to deploy webservice
• How to create ActiveX Control
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• Help with dll call
• Hardware IDs
• Multiple Inheritence
• .exe quits after user input, when it is
• get duration form WMA & WMV
• Executing aspx files not working
• install fails for c# 2003 standard
• Resetting d3device error
• Does the event Collapse in Contextmenu w
• How to increase the performance of Custo
• Delete controle does not remove code
• Detect processes initialization
• Deployment
• Help : Using comboBox and KeyPress event
• cannot integrate paypalin c#

Hot Articles

• Article on Threading in C#
• Validation expression for a RegularExpre
• Defining a DLL entry point in C#? (DLLEX
• Registering Remote Com+ Serviced Component
• What is the difference between debug mod
• <E2ETraceEvent> when using XMLWrit
• using a PointF type object in a Property
• Using ToolStripContainer as MDI container
• Modify Unix Attributes for ADS users in C#
• Splitting Tiff Files...HELP!!!
• FileStream in WinForm(web)
• Implementing IDisposible, question mainl
• Button Properties vs. Form Properties
• Localization in visual studio 2005, .resx
• Correct me!

Recommend Articles

• (INTEGRATE) Convert a string to a Function
• upper case
• Is it possible to use .NET controls to V
• Please Help me in my application problem ?
• Redirect Standard Input
• Saving a Solution
• User Controls
• how to browse a directory?
• Exe path from file extension
• loading array in treeview
• HtmlDocument and Object Tag
• how to control AudioVideoPlayer output t
• Converting '00' hex character into '20'
• MessageBoxIcon.Hand not working as expec
• Problem with printing