Connecting Tech Pros Worldwide Help | Site Map

Global variables in VC#.net windows application

  #1  
Old January 27th, 2007, 06:20 PM
Newbie
 
Join Date: Dec 2006
Posts: 21
Hi!
I want to use some variables throughout my VC#.net windows based application...........
How can i declare global variables that will work throughout my project...
-Regards
  #2  
Old January 28th, 2007, 12:26 PM
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745

re: Global variables in VC#.net windows application


I recommend declaring them in the application_start event of the global.asax file. This article may help if you are unfamiliar with the ASP.NET application file:
Global.asax Syntax
  #3  
Old January 29th, 2007, 09:12 AM
almaz's Avatar
Expert
 
Join Date: Dec 2006
Location: Kyiv, Ukraine
Posts: 167

re: Global variables in VC#.net windows application


Quote:
Originally Posted by rhyme2ri2
Hi!
I want to use some variables throughout my VC#.net windows based application...........
How can i declare global variables that will work throughout my project...
-Regards
Global variables, especially those being updated from various parts of application, make your code unreadable. General thoughts that should be considered when you want to declare something to be globally available:
  • Each variable is bound to some functionality. Thus, it is better to put it to corresponding class as static/instance member, so it will be maintained through methods/properties of that class.
  • Static members containing common values that are changed from different places of application can brake encapsulation rule.
Nevertheless it may be useful to separate common constants/settings to a separate internal static class, something like this:
Expand|Select|Wrap|Line Numbers
  1. internal static class Constants
  2. {
  3.     public static int UndefinedID = int.MinValue;
  4.  
  5.     public bool IsDefined(int id) { return id != UndefinedID; }
  6. }
  7.  
  #4  
Old January 30th, 2007, 04:18 AM
Needs Regular Fix
 
Join Date: Jul 2006
Location: India,Hyderabad
Posts: 367

re: Global variables in VC#.net windows application


hello kenobewan

i want to how you can have a global.asax file in windows based application

as you have said in the above reply.


please tell me if its possible it is very use full for me too.


regards
NMsreddi
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialize global variable before any other global variables jubelbrus answers 4 July 20th, 2007 02:15 PM
Asp.net Important Topics. shamirza answers 0 January 18th, 2007 05:15 AM
Is There Any Reason to Even Use VC++ Anymore? Greg answers 37 December 9th, 2005 08:37 PM
Debugging / Single Step into event procedures R Millman answers 3 November 17th, 2005 08:02 PM