《MCTS.C#》(part.3)第四章:方法與運算子 method & operator
本週重點:
Reference Type有宣告ref 跟 沒有宣告,還是有差的。
Method的具名參數及選擇性參數(C# 4.0 以上)
================================================
參數的傳遞
輸入參數
Value Type
Reference Type
object
傳入Method後,當object沒有new instance時,會變更原始的object。但若有new新的instance時,即會複製一個新的,並不會變更原始的object。
※若為ref 參考參數時,即使new新的instance,仍會變更原來的物件。因為他是直接拿外部的參數來使用的。
String
在Method只要有對string重新設定值時,即為new 新的instance。結果同b1,並不會更改到外部的參數值。
參考參數
無論是否有new instance,皆會改變原始的外部參數值。
static void Main(strin[……]
