C#——语言基础 之 数据类型!

一,数据类型

        基本数据类型(值类型) 

                                     整型:1有符号(带负号)  (1)int(32位)                   赋值形式: int  _Int=+1或-1;

                                                                        (2)long(64位)

                                              2无符号 (0和正数)(1)ulong(64位)                     

                                                                         (2)uint(32位)

 

                                    浮点型:   1 float(32位)                                               赋值形式:float  _Float=123.99F;

                                                 2 double(64位)                                          赋值形式:double  _Double=1.99

                                    字符型:char(16位),用单引号引起来                            赋值形式:char _Char='g';//单字节节省内存

                                    布尔型 :bool  1 true                                                  赋值形式:bool _zhen=true

                                                       2 false                                                  赋值形式:bool _jia=false

                                    结构型:1 struct

                                              2 DateTime(1)Now当前时间,Today当前日期    赋值形式:DateTime dt=DateTime.Now; DateTime today=DateTime.Today;

                                                              (2)转换格式:ToString(yyyyMMdd HH:mm:ss)

                                                                    赋值形式:Consloe.WriteLine("dt"+dt.Tostring(yyyy-MM-dd HH-mm-ss));

                                                                                   Consloe.WriteLine("dt"+dt.Tostring(yyyy年MM月dd日));

                                    枚举enum: 基础类型为整型(一般为Int型)

         引用类型               

                              字符串 string                    赋值形式:string a="hello";               // 字符串 定义是双引号

                              类,接口 object                 赋值形式:aaa=_Int ;                      //装箱

                                                                           int i=(int)aaa;                          //拆箱

                              数组                                赋值形式: string[] strA=new string[]{"assdds","ertert","ghgjgh"};

                                                                                   string[] strB=strA;

                                                                                    strA[0]="assdds";

                                                                                   Console.WriteLine("strA[0]的值"+strA);

                                                                                   Consloe.WriteLine("strB[0]的值"+strB);

                              集合 ArrayList,Queue(队列),Stack(栈),Hashtable(哈希表)

 

补充:计算机存储单位 Byte(字节)与Bit(比特)之间的关系

                        1Byte=8 Bit

                        1比特=1位二进制数:0或1

           1字节(Byte)=8比特(位,位元)=8位连续的二进制数字;01010011

 

二,转义字符

                      反斜杠:Consloe.WriteLine("\"strTest\"的值"+strTest);

                                Consloe.WriteLine("\strTest\n的值"+strTest);Consloe.Write("转义字符换行:\n"   )

                     整句转义:@符号转义,例子@("H:\\音乐\\喜剧\\郭德纲");

                                         转义输出效果:H:\\音乐\\喜剧\\郭德纲

 

三,变量名前加关键字(不能赋值,只能取值);const      例如:const  int a=1

 

四,基本的类型转换

               1,自动转换(隐式转换)———从值类型转换到引用类型

               2,强制转换(显示转换)———从引用类型转换到值类型或从浮点型转换到整型

              注意:当从一个引用类型转换到值类型时,引用类型中的数据元素必须能够转换到值类型的容量范围内的数据才可以,否则不行!!

转换方式 1,用()

            例子:int a; double b=12.3;  a=(int)b;

            2,用convert;

            例子:a=Convert.ToInt32(b);

            3,用parse;

            例子:a=int.parse(b);

                                                   

 

                                                                    要做就选的自己能拿第一的事业!

 

posted on 2015-08-02 16:47  闫科达  阅读(154)  评论(0编辑  收藏  举报

导航