第一节 赋值和常用数据类型。向控制台输出HelloWorld

 

View Code
//案例1:向控制台输出 HelloWorld

using System ;   //导入命名空间
public class HelloWorld  //声明一个类,类名:HelloWorld
{ 
public static void Main()  //声明主函数
    { 
           Console.WriteLine("HelloWorld !");//用于向控制台输出:“HelloWorld !”
   }
}
View Code
//案例2 :赋值

//变量的声明
            //创建整型的变量,=赋值运算符
            int i = 10;

            //先声明,后赋值
            int j;
            j = 20;

            Console.WriteLine(i);
            Console.WriteLine(j);

            Console.WriteLine("重新赋值后:");

            //重复赋值
            i = 100;
            j = 200;

            Console.WriteLine(i);
            Console.WriteLine(j);

            Console.ReadKey();
View Code
//案例三 :数据类型

//数据类型 标识符=值

            //整型
            int i = 10;

            //单精度浮点型
            float f = 3.4F;

            //字节型
            byte b = 255;

            //短整型
            short sh = 3275;

            //长整型 
            long l = 545545454545455;

            //布尔型
            bool bf = false;
            bool bt = true;

            //字符串
            string str = "你好!谢谢";

            //双精度浮点型
            double d = 3.14156906;

            // 十进制小数
            decimal dec = 3.14M;

            //字符型
            char c = 'j';
            Console.WriteLine("整型:" + i);
            Console.WriteLine("单精度浮点型:" + f);
            Console.WriteLine("字节型:" + b);
            Console.WriteLine("短整型:" + sh);
            Console.WriteLine("长整型:" + l);
            Console.WriteLine("布尔型;" + bf+","+bt);
            Console.WriteLine("字符串:" + str);
            Console.WriteLine("双精度浮点型:" + d);
            Console.WriteLine("十进制小数:" + dec);
            Console.WriteLine("字符型:" + c);

变量命名规范:

开头:字母或下划线

不能使用关键字

posted @ 2012-06-19 09:57  ComBat  阅读(181)  评论(0编辑  收藏  举报