|
-
Jan 17th, 2003, 05:21 AM
#1
Thread Starter
Member
Global Variables in C#
moving from VB6 to C#, is there an equivalent 'mod' module you can add to the project to hold global variables or are global variables not permitted in C#.
If globals are not allowed, then how can I store a connection to the database and use it in different forms and classes?
-
Jan 17th, 2003, 07:09 AM
#2
Frenzied Member
Use a utitily class. Make a sealed class with the variables that you want to be global, then use can use that class anywhere in your project.
Dont gain the world and lose your soul
-
Jan 17th, 2003, 07:28 AM
#3
Frenzied Member
u can use static variables...
here is an example
code came right from the source of my app (iCodeLibrary)
PHP Code:
/// <summary>
/// Summary description for GlobalStuff.
/// </summary>
public class GlobalStuff
{
public static string ProgramDirectory = Environment.CurrentDirectory;
public static string AccessDBPath = ProgramDirectory + @"\DB\iCodeLibrary.MDB";
public static string DBType = "Access";
public static string LastAccessedDirectory = @"c:\";
public static string AttachmentsDirectory = ProgramDirectory + @"\Attachments\";
public static string SettingsFile = ProgramDirectory + @"\settings.xml";
public static bool IsSettingChanged = false;
private GlobalStuff()
{
}
}
how do you use them?
just do GlobalStuff.AttachmentDirectory
i put mine in a glass cus its more organized and i know when i am using a global variable or method cus of GlobalStuff.
-
Jan 17th, 2003, 03:43 PM
#4
PowerPoster
I have something you might be interested posted at my site:
http://www.russellsplace.com/variant...ptutorials.htm
I use it to store APP settings in the registry. You can modify it easily to store the settings into an XML file.
-
Jan 21st, 2003, 10:52 AM
#5
Thread Starter
Member
Thanks for everyones help. That was great.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|