变量类型
-
值类型
- bool 布尔型
- btye 8位无符号整数 0x00~0xff
- char 16位无符号整数
- decimal 128位精确的10进制值
- double 64位
- float 32 位
- int 32位
- long 64位
- sbyte 8位有符号
- short 16位
- uint 32位无符号
- ulong 64位无符号
- ushort 16位无符号
sizeof 可以获取变量的位数
- 引用类型
- 引用类型不包含存储在变量中的值,引用类型指向内存位置
- 内置的引用类型有 object dynamic string
- 对象类型
- 动态类型
- 可以存储任何类型的值到变量中,在运行时生效
- 字符串类型
- String str= “Helloworld“;
- 加引导字符@ ,可以把字符串中的 ‘\'字符看待 @"\\HelloWorld" == “\HelloWorld”
- 字符串可以任意换行,空格键和换行符都算在字符串长度之内
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StudentCShrap { class MainClassTest { static void Main(string[] args) { String str = "Helloworld\n\n\n"; Console.WriteLine(str.Length);//13 length str = @"12345897522 4152454 524154"; Console.WriteLine(str.Length);//72 length Console.ReadKey(); } } }
- 指针类型
- 存储另一种类型的内存地址 跟C和C++的指针有相同的作用
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StudentCShrap { class MainClassTest { static void Main(string[] args) { int* Leng; //错误 CS0214: 指针和固定大小缓冲区只能在不安全的上下文中使用 Console.ReadKey(); } } }
- 存储另一种类型的内存地址 跟C和C++的指针有相同的作用