PC Review


Reply
Thread Tools Rate Thread

Where i can define global variable?

 
 
Tark Siala
Guest
Posts: n/a
 
      19th Nov 2007
hi
i worked with VB6 then i changed to C#.
i want define Variable thats i can accessed from any Form or Class in my
project.
in VB6 you can do that by define as "Global" in Module, but in C# i can't
find Global for all forms in project.
-----------
Tarek M. Siala
Software Developer
http://tarksiala.blogspot.com


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      19th Nov 2007
On Nov 19, 12:44 pm, "Tark Siala" <tarksi...@icc-libya.com> wrote:
> i worked with VB6 then i changed to C#.
> i want define Variable thats i can accessed from any Form or Class in my
> project.
> in VB6 you can do that by define as "Global" in Module, but in C# i can't
> find Global for all forms in project.


You can use a "public static" variable, or "public const" where
appropriate.
You'll need to explicitly state which type contains the variable from,
though. For instance, in SomeForm.cs you might say

label.Text = TypeContainingGlobals.SomeGlobalName;

Jon
 
Reply With Quote
 
rossum
Guest
Posts: n/a
 
      19th Nov 2007
On Mon, 19 Nov 2007 14:44:33 +0200, "Tark Siala"
<(E-Mail Removed)> wrote:

>hi
>i worked with VB6 then i changed to C#.
>i want define Variable thats i can accessed from any Form or Class in my
>project.
>in VB6 you can do that by define as "Global" in Module, but in C# i can't
>find Global for all forms in project.
>-----------
>Tarek M. Siala
>Software Developer
>http://tarksiala.blogspot.com
>

Try:

public static class MyGlobals {
public static int myInt = 42;
public static string myString = "Armadillo";
}

rossum

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
define global value .nLL Microsoft ASP .NET 5 25th Aug 2008 02:44 PM
How to define 'Global' variables in a .NET app? John Smith Microsoft Dot NET Framework Forms 9 17th Nov 2005 07:07 PM
Define Global Variable? =?Utf-8?B?TWU=?= Microsoft Access Form Coding 3 17th Nov 2004 11:29 PM
Is it possible to define global variable in select Tina Microsoft Access Security 2 12th May 2004 04:55 AM
define global var to use throughout vb proj Steve Microsoft ASP .NET 5 17th Mar 2004 09:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 PM.