Click here to Skip to main content
15,899,024 members
Home / Discussions / C#
   

C#

 
GeneralRe: i have the same problem also Pin
Polis Pilavas14-May-05 8:10
Polis Pilavas14-May-05 8:10 
GeneralSmall question Pin
snouto14-May-05 7:42
snouto14-May-05 7:42 
GeneralRe: Small question Pin
Polis Pilavas14-May-05 8:01
Polis Pilavas14-May-05 8:01 
GeneralRe: Small question Pin
snouto14-May-05 8:11
snouto14-May-05 8:11 
GeneralRe: Small question Pin
Polis Pilavas14-May-05 8:14
Polis Pilavas14-May-05 8:14 
GeneralRe: Small question Pin
snouto14-May-05 8:19
snouto14-May-05 8:19 
GeneralRe: Small question Pin
MoustafaS14-May-05 10:28
MoustafaS14-May-05 10:28 
GeneralRe: Small question Pin
mav.northwind14-May-05 20:25
mav.northwind14-May-05 20:25 
The key to what you need is a concept of "static" members.
static members are those that are shared among all instances of a class and are declared using the static keyword.
You can access these static members by just using the classname of the containing class, instead of the variable name holding an instance for instance members.
You can even initialize these static members in the static class initializer that's executed when the class is first loaded by the CLR.
For example:
class MyGlobals
{
  static string UserName;
  static DateTime LogonTime;

  static MyGlobals()
  {
    UserName = "Not set";
    LogonTime = DateTime.MinValue;
  }
}
Then you can simply do this:
class MainProgram
{
  public static void Main()
  {
    Console.WriteLine("Username is " + MyGlobals.UserName);
  }
}
This will give you "Not set" without any previous initialization in your MainProgram class.

Regards,
mav
GeneralRe: Small question Pin
lgstef16-May-05 1:31
lgstef16-May-05 1:31 
GeneralAsynchronous file transfer client/server Pin
methodincharge14-May-05 7:37
methodincharge14-May-05 7:37 
GeneralRe: Asynchronous file transfer client/server Pin
snouto14-May-05 7:49
snouto14-May-05 7:49 
GeneralCatching event before file opens Pin
krisst_k14-May-05 3:43
krisst_k14-May-05 3:43 
GeneralRe: Catching event before file opens Pin
MoustafaS14-May-05 7:10
MoustafaS14-May-05 7:10 
GeneralRe: Catching event before file opens Pin
krisst_k14-May-05 14:23
krisst_k14-May-05 14:23 
GeneralRe: Catching event before file opens Pin
Dave Kreskowiak15-May-05 5:51
mveDave Kreskowiak15-May-05 5:51 
GeneralPerformanceCounter Problem Pin
Zishan Haider14-May-05 3:23
Zishan Haider14-May-05 3:23 
GeneralDatabase WebService Pin
Yeast2714-May-05 2:49
Yeast2714-May-05 2:49 
GeneralRe: Database WebService Pin
Zishan Haider14-May-05 3:25
Zishan Haider14-May-05 3:25 
GeneralRe: Database WebService Pin
Roger Wright14-May-05 3:30
professionalRoger Wright14-May-05 3:30 
Generalclasses programing Pin
eng.mohamed14-May-05 0:29
eng.mohamed14-May-05 0:29 
GeneralRe: classes programing Pin
Colin Angus Mackay14-May-05 0:42
Colin Angus Mackay14-May-05 0:42 
GeneralRe: classes programing Pin
snouto14-May-05 7:45
snouto14-May-05 7:45 
GeneralC# Interop with C++ classes Pin
Julien Delezenne13-May-05 17:20
Julien Delezenne13-May-05 17:20 
GeneralReference 64bit COM Object from C# Pin
Phan Chau13-May-05 11:39
Phan Chau13-May-05 11:39 
Generalnewbie question Pin
Tom Wright13-May-05 10:58
Tom Wright13-May-05 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.