what is the use of static keyword?
what is the use of static keyword and why we are writing only static word in main method["static void main [string[] args"]?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raja TPosted Nov 30, 2015, 12:44 AM
Finally i understand the static variable.....static variable shared the value of it among all instances of the class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static int a; // initialized at the time of declaration
public static int Hello()
{
a = 20;
return a;
}
}
class run
{
static void Main(string[] args)
{
//Program p = new Program();
Console.WriteLine(Program.Hello());
}
}
}
Output
20
Ravi PatelPosted Nov 30, 2015, 12:42 AM
for more details check following link
Jignesh TrivediPosted Nov 30, 2015, 12:22 AM