变量的作用域(3)
namespace ConsoleApplication3
{
class Program
{
static string mystring;
static void write()
{
string mystring = "string defined in wrtie()";
Console.WriteLine("now in write()");
Console.WriteLine("Local mystring={0}", mystring);
Console.WriteLine("Global mystring={0}",Program.mystring );
}
static void Main(string[] args)
{
string mystring = "string defined in Main()";
Program.mystring = "global string";
write();
Console.WriteLine("\nnow in Main()");
Console.WriteLine("Local mystring={0}", mystring);
Console.WriteLine("Global mystring={0}", Program.mystring);
Console.ReadKey();
}
}
}