Interview Questions

How do you declare a static variable and what is its lifetime? Give an example.

.NET Database ,COM interop,and .NET deployment questions and answers


(Continued from previous question...)

How do you declare a static variable and what is its lifetime? Give an example.

Answer1
static int Myint–The life time is during the entire application.
br> Answer2
The static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs.

Example
a. Static int var //in c#.net
b. static void Time( ) //in c#.net

(Continued on next question...)

Other Interview Questions