How do u declare static variable and how it is declared and what is its lifetime?

Showing Answers 1 - 7 of 7 Answers

Bhasker Das

  • Sep 20th, 2005
 

By using keyword static before the variable name. Static variable retains the same data throughout the execution of a program.

  Was this answer useful?  Yes

guest

  • Aug 6th, 2011
 

Yes it is possible to change the value of static variable. Here is the sample code how you can do that

Try this:

Code
  1. namespace ConsoleApplication1

  2. {

  3.     class Program

  4.     {

  5.         public static string st = "static";

  6.  

  7.         static void Main(string[] args)

  8.         {

  9.             st = "non statick";

  10.             Console.WriteLine(  st);

  11.             Console.Read();

  12.         }

  13.     }

  14. }

  Was this answer useful?  Yes

rajiii

  • Aug 9th, 2011
 

by using static keyword we can declare static variable and its lifetime is the life of the program

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions