C#引用类型和值类型的介绍与实例
时间:2022-08-11 16:24:34
static void Main(string[] args)
{
//值类型
bool b1 = true; //栈中划一块内存,名字为b1,类型为bool,值为true
Console.WriteLine("b1="+b1); // b1 =true
bool b2 = b1; //栈中划一块内存,名字为b2,类型为bool,和b1的值一样为ture
Console.WriteLine("b2="+b2); // b2 = false
b1 = false; //将栈中b1的值改为false
Console.WriteLine("b1=" + b1); // b1 = false
Console.WriteLine("b2=" + b2); // b2 = true
Console.ReadKey();
//引用类型
int[] a1 = { 1, 2, 3 }; //栈中划一块内存,名字为a1,类型为int[],值为一个地址
//堆中划连续3个int空间,将首地址赋给栈的值
Console.WriteLine("a1[1]=" + a1[1]);
int[] a2 = a1; //栈中划一块内存,名字为a1,类型为int[],值的地址为数组a1的地址
Console.WriteLine("a2[1]=" + a2[1]);
a1[1] = 9; //根据地址修改,堆中的数据
Console.WriteLine("a1[1]=" + a1[1]);
Console.WriteLine("a2[1]=" + a2[1]);
Console.ReadKey();
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# 在PDF中创建和填充域
![](https://img.aspxhome.com/file/2023/7/79117_0s.png)
Opencv图像处理之轮廓外背景颜色改变
Java事务的个人理解小结
C#制作二维柱状图方法
![](https://img.aspxhome.com/file/2023/9/111169_0s.png)
Android如何遍历特定目录下所有文件
spring中的FactoryBean代码示例
Java中高效判断数组中是否包含某个元素的几种方法
HashMap在JDK7与JDK8中的实现过程解析
![](https://img.aspxhome.com/file/2023/7/132117_0s.png)
C#泛型集合类System.Collections.Generic
Android实现ImageView阴影和图层效果
![](https://img.aspxhome.com/file/2023/1/125411_0s.jpg)
spring解决循环依赖的方案示例
![](https://img.aspxhome.com/file/2023/8/68018_0s.png)
C#多线程学习之Thread、ThreadPool、Task、Parallel四者区别
![](https://img.aspxhome.com/file/2023/2/108772_0s.png)
c#和avascript加解密之间的互转代码分享
Android带进度条的文件上传示例(使用AsyncTask异步任务)
![](https://img.aspxhome.com/file/2023/4/72624_0s.png)
Android控件之SeekBar的用法总结
![](https://img.aspxhome.com/file/2023/3/137583_0s.png)
Unity实现粒子光效导出成png序列帧
Java中输入与输出的方法总结
![](https://img.aspxhome.com/file/2023/4/63854_0s.png)
Android UI控件Switch的使用方法
![](https://img.aspxhome.com/file/2023/4/139234_0s.jpg)
详解C#中三个关键字params,Ref,out
![](https://img.aspxhome.com/file/2023/1/104261_0s.png)
Android基础之隐藏标题栏/设置为全屏/横竖屏切换
![](https://img.aspxhome.com/file/2023/8/137468_0s.jpg)