Connecting Tech Pros Worldwide Help | Site Map

Global variables in VC#.net windows application

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 27th, 2007, 05:20 PM
Newbie
 
Join Date: Dec 2006
Posts: 21
Default Global variables in VC#.net windows application

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
Reply
  #2  
Old January 28th, 2007, 11:26 AM
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
Default

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
Reply
  #3  
Old January 29th, 2007, 08:12 AM
almaz's Avatar
Expert
 
Join Date: Dec 2006
Location: Kyiv, Ukraine
Age: 28
Posts: 167
Default

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.  
Reply
  #4  
Old January 30th, 2007, 03:18 AM
Needs Regular Fix
 
Join Date: Jul 2006
Location: India,Hyderabad
Age: 28
Posts: 367
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.