logo
  • 教程列表
  • SO官方文檔
  • 值型別與引用型別
    • 使用 ref 關鍵字通過引用傳遞
    • 改變別處的值
    • 通過引用傳遞
    • 分配
    • 與方法引數 ref 和 out 的區別
    • ref vs out 引數
  1. StackOverflow 文件
  2. C# Language 教程
  3. 值型別與引用型別
  4. 分配

分配

Created: November-22, 2018

var a = new List<int>();
var b = a;
a.Add(5);
Console.WriteLine(a.Count); // prints 1 
Console.WriteLine(b.Count); // prints 1 as well

分配給 List<int> 的變數不會建立 List<int> 的副本。相反,它將引用複製到 List<int>。我們呼叫以這種方式表示引用型別的型別。

  • 與方法引數 ref 和 out 的區別
  • 通過引用傳遞

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明