//最后面都有源码的下载地址。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace _4值类型和引用类型的分析 { class Program { static void Main(string[] args) { //值类型,观察a的值 int a = 20; int b = a; b += 5;
//引用类型,观察score1的值得变化 int[] score1 = { 29, 79, 30, 12 }; int[] score2 = score1; score2[0] = score1[3] + 100; for (int i = 0; i < score1.Length; i++) { Console.WriteLine(score1[i]); } //ref 和 out, ref是有进有出,out是只出不进。 int val = 0; Method(ref val); // val is now 44 int value; Method1(out value); // value is now 44 Console.Read(); } static void Method(ref int i) { i = 44; } static