"Global Variable Scope if i declared it as a Public then we can access through out the Project
is this correct or not"
Yes - and no.
More "No" in actual fact.
C# has no concept of global variables, they do not exist. Everything in C# is contained within a class of some form, in some way. So adding
public
does not make a variable a global variable in the sense that declaring it outside of a class does in C++, or declaring it outside a method or function, but in a module does in VB.
What declaring a variable as public does is:
1) Annoy people who have to maintain your code - you should keep variables (or fields as they are better known) private and expose any access to them via properties instead.
2) Make the variable available outside the class. This is not the same as a global variable, because it still requires a class instance to access it:
public class MyClass
{
public int MyInt = 666;
}
...
MyClass mc = new MyClass();
Console.WriteLine(mc.MyInt);
So in answer to your three questions:
1) Nonexistent - C# does not support global variables.
2) From creation of the variable to the end of the application.
3) Assuming you mean "Instant Variable" to mean one declared within a method, it depends on what happens to it. If it is a value type, then it's lifetime is that of the method itself (or less if it goes out of scope). If it is a reference type, then it will become available for disposal when it goes out of scope, assuming you do not pass a reference to it out of the method. The actual lifetime of any reference type is indeterminate as it wholly depends on the Garbage Collector execution cycle if it is not explicitly Disposed.
[edit]dunno what happened there - code block all wierd... - OriginalGriff[/edit]