Are ILists passed by value?

后端 未结 6 1202
谎友^
谎友^ 2020-12-16 05:26

Passing Value Type parameters to functions in c# is by value unless you use the ref or out keyword on the parameter. But does this also apply to Reference Types?

Sp

6条回答
  •  轮回少年
    2020-12-16 05:43

    The list is passed by reference, so if you modify the list in SomeFunction, you modify the list for the caller as well.

    You can create a copy of a list by creating a new one:

    var newList = new List(oldList);
    

提交回复
热议问题