namespace 值类型和引用类型
{
internal class Program
{
static void Main(string[] args)
{
//无符号整型
byte byte1 = 1;
ushort ushort1 = 1;
uint uint1 = 1;
ulong ulong1 = 1;
//有符号整型
sbyte ubyte1 = 1;
short short1 = 1;
int int1 = 1;
long long1 = 1;
//浮点数
float float1 = 1f;
double double1 = 1d;
decimal decimal1 = 1m;
//其他类型
bool bool1 = true;
char char1 = 'A';
string string1 = "string111";
//复杂类型
//枚举enum
//数组(一维,多维)
//引用类型:string、数组、类
//值类型:其他、结构体
//值类型 -- 栈内存 -- 系统分配,自动回收,小、快
//引用类型 -- 堆内存 -- 手动申请和释放,大、慢
#region 特殊引用类型
//string的它变我不变
string str1 = "123";
string str2 = str1;
str1 = "321";
Console.WriteLine("str1:{0}, str2:{1}", str1, str2);//>str1:321, str2:123
//string类型重新赋值就相当于new了,或者说是换了一个地址。
#endregion
#region 监测地址
//处于调试状态时,在调试(D)中窗口开启监视。
#endregion
}
}
}
C#基础-值类型和引用类型
于 2025-03-26 21:44:14 首次发布

被折叠的 条评论
为什么被折叠?



