C#學習筆記(基礎知識回顧)之值類型和引用類型
class Program { static void Main(string[] args) { StringBuilder str = new StringBuilder(); str.Append("hello"); AddOne(str); Console.WriteLine("num的值為:" + str);//輸出值為hello,word Console.ReadKey(); } public static void AddOne(StringBuilder sb) { sb.Append(",world"); } }
class Program { static void Main(string[] args) { StringBuilder str = new StringBuilder(); str.Append("hello"); AddOne(str); Console.WriteLine("str的值為:" + str);//輸出值為hello Console.ReadKey(); } public static void AddOne(StringBuilder sb) { sb = new StringBuilder(); sb.Append(",world"); } }View Code
class Program { static void Main(string[] args) { StringBuilder str = new StringBuilder(); str.Append("hello"); AddOne(ref str); Console.WriteLine("str的值為:" + str);//輸出值為,world Console.ReadKey(); } public static void AddOne(ref StringBuilder sb) { sb = new StringBuilder(); sb.Append(",world"); } }View Code
C#學習筆記(基礎知識回顧)之值類型與引用類型轉換(裝箱和拆箱)