From: Arne Vajhøj on 26 Jun 2010 08:20 On 26-06-2010 04:41, Stefan Ram wrote: > In Java, there are some names that refer to objects that > are already created when a program starts. For example, > > java.lang.System.out > > refers to an object at and after program startup, this object > does not have to be created by a program, but already exists > when the main method is being started. > > Are there any such identifiers in C# (that refer to objects > already existing at program startup)? If you will accept properties then an obvious one would be: System.Console.Out If you specifically want a field then it becomes much harder. But they exist. String.Empty, numbertypes.MaxValue and numbertypes.MinValue etc.. Arne
From: David Boucherie & Co on 26 Jun 2010 12:46 Short answer: Yes. =) Long answer: In principle, any class methods and properties "exist" before you use them (as opposed to instance methods and properties that are only accessible on instances that have to be created during runtime). Class methods and properties are declared with the static keyword. In reality, those "statics" are initialized during runtime, so you can use static constructors, but they are guaranteed to be initialized before you actually use them. The order in which they are initialized is non-deterministic, though, so you can't count on a certain sequence order of initialization. A whole class can also be declared static, in which case they can only contain static members and cannot be instantiated. Examples of static classes provided by the .NET framework and some of the objects they contain (and consequently exist without your program having to create them): System.Console · Represents the standard input, output, and error streams for console applications · Properties ··· In: Gets the standard input stream. ··· Out: Gets the standard output stream. ··· Title: Gets or sets the title to display in the console title bar. System.Convert · Converts a base data type to another base data type. ··· DBNull: A constant representing a database null. System.Environment · Provides information about, and means to manipulate, the current environment and platform. ··· MachineName: Gets the NetBIOS name of this local computer. ··· OSVersion: Gets an OperatingSystem object. ··· UserName: Gets the user name of the person currently logged on. System.GC · Controls the system garbage collector, ··· MaxGeneration: Gets the maximum number of generations (duh). System.Math · Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions. ··· E: Represents the natural logarithmic base (e). ··· PI: Represents the constant π. Etc. I told you... long answer. Stefan Ram wrote: > In Java, there are some names that refer to objects that > are already created when a program starts. For example, > > java.lang.System.out > > refers to an object at and after program startup, this object > does not have to be created by a program, but already exists > when the main method is being started. > > Are there any such identifiers in C# (that refer to objects > already existing at program startup)? >
From: Raj on 28 Jun 2010 08:29 Rightly said! Regards Raj "David Boucherie & Co" wrote: > Short answer: > > Yes. =) > > > Long answer: > > In principle, any class methods and properties "exist" before you use > them (as opposed to instance methods and properties that are only > accessible on instances that have to be created during runtime). > > Class methods and properties are declared with the static keyword. > > In reality, those "statics" are initialized during runtime, so you can > use static constructors, but they are guaranteed to be initialized > before you actually use them. > The order in which they are initialized is non-deterministic, though, so > you can't count on a certain sequence order of initialization. > > A whole class can also be declared static, in which case they can only > contain static members and cannot be instantiated. > > Examples of static classes provided by the .NET framework and some of > the objects they contain (and consequently exist without your program > having to create them): > > System.Console > · Represents the standard input, output, and error streams for console > applications > · Properties > ··· In: Gets the standard input stream. > ··· Out: Gets the standard output stream. > ··· Title: Gets or sets the title to display in the console title bar. > > System.Convert > · Converts a base data type to another base data type. > ··· DBNull: A constant representing a database null. > > System.Environment > · Provides information about, and means to manipulate, the current > environment and platform. > ··· MachineName: Gets the NetBIOS name of this local computer. > ··· OSVersion: Gets an OperatingSystem object. > ··· UserName: Gets the user name of the person currently logged on. > > System.GC > · Controls the system garbage collector, > ··· MaxGeneration: Gets the maximum number of generations (duh). > > System.Math > · Provides constants and static methods for trigonometric, logarithmic, > and other common mathematical functions. > ··· E: Represents the natural logarithmic base (e). > ··· PI: Represents the constant π. > > Etc. > > I told you... long answer. > > > Stefan Ram wrote: > > In Java, there are some names that refer to objects that > > are already created when a program starts. For example, > > > > java.lang.System.out > > > > refers to an object at and after program startup, this object > > does not have to be created by a program, but already exists > > when the main method is being started. > > > > Are there any such identifiers in C# (that refer to objects > > already existing at program startup)? > > > . >
|
Pages: 1 Prev: Drag-and-drop between two ListView controls? Next: C#.net custom control |