using System;
using System.Collections.Generic;
using System.Text;
//程序作用:这里测试变量作用范围
namespace ConsoleApplication17
{
    class Program
    {
        //const定义的全局变量是不允许更改的,如果要改,可以用: static string constStr = "this is constStr";
        const string constStr = "this is constStr";
        static void test()//函数里面定义的变量只能在函数中用
        {
           // const string constStr = "this is constStr"; 函数里面是不能声明全局变量的。
            string testStr = "this is testStr";
            Console.WriteLine("{0}",testStr);
        }
        static void Main(string[] args)
        {
            test();
            string mainStr = "this is mainStr";
            Console.WriteLine("{0}", mainStr);
            Console.WriteLine("{0}", constStr);
         }
    }
}
http://hi.baidu.com/ecspell/blog/item/850af9f2f5fcdc13b17ec553.html
posted on 2007-06-29 13:37  mbskys  阅读(1244)  评论(0)    收藏  举报