/** * 值类型演示
* 前面介绍的基本数据类型都是值类型,到目前为止,我们学过的引用类型只有字符串和数组,
* 值类型的存储空间是分配在栈(stack)中,引用类型的存储空间是分配在堆(heap)中。数组属于引用类型 * */
int num1 = 100;
int num2 = num1;
num1 = 50;
Console.WriteLine("num1={0},num2={1}",num1,num2); //引用类型的演示
int[] arr1 = { 1, 3, 5, 7, 9 };
int[] arr2 = arr1;
arr1[0] = 500;
Console.WriteLine("arr1的值是:");
for (int i = 0; i < arr1.Length; i++)
{
Console.Write(arr1[i]+",");
}
Console.Write("arr2的值是:");
for (int i = 0; i < arr2.Length; i++)
{
Console.Write(arr2[i]+",");
}
Console.ReadKey();