Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
#region 知识点一 复习值和引用类型
|
||||
// 值类型-他变我不变,存储在栈内存中
|
||||
// 无符号整形,有符号整形,浮点数,char,bool,结构体,enum
|
||||
|
||||
// 引用类型-他变我也变,存储在堆内存中
|
||||
// string,数组,类
|
||||
#endregion
|
||||
|
||||
#region 知识点二 string类型的特殊性
|
||||
string str1 = "123";
|
||||
string str2 = str1;
|
||||
//因为string是引用类型,所以str2和str1应该是指向同一个地址的
|
||||
str2 = "321";
|
||||
Console.WriteLine(str1);
|
||||
Console.WriteLine(str2);
|
||||
//但是输出结果是str1=123,str2=321
|
||||
//原因:string类型是不可变类型
|
||||
//修改,或重新给string类型赋值时,重新开辟了一块堆内存空间来存储新的值
|
||||
//当str2重新指回"123"时,str2和str1才会指向同一个地址
|
||||
//但是堆内存中原来存储"321"没被引用,就变成了垃圾,等待垃圾回收器来回收
|
||||
|
||||
//所以string会有优化替代的方案(后面教)
|
||||
#endregion
|
||||
|
||||
#region 补充知识点 断点调试
|
||||
//通过断点调试 在监视窗口中查看内存信息
|
||||
//断点:窗口最左侧红点
|
||||
//调试->窗口->监视
|
||||
//F10逐步执行
|
||||
string str4 = "123";
|
||||
string str5 = str1;
|
||||
str5 = "321";
|
||||
Console.WriteLine(str4);
|
||||
Console.WriteLine(str5);
|
||||
#endregion
|
||||
Reference in New Issue
Block a user