gpt4 book ai didi

c# - 方法参数引用与否

转载 作者:行者123 更新时间:2023-12-02 04:50:30 25 4
gpt4 key购买 nike

<分区>

有人可以解释一下吗,我认为当我用 ref 显式执行它时,它只是被 ref 传递了?

var user = new User { Name = "MyName" };
ChangeNameToOtherName(user); // After method call user.name is "OtherName" < confusing
ChangeNameToOtherName(ref user); // After method call user.name is "OtherName"

var name = "MyName";
ChangeNameToOtherName(name); // After method call name is "MyName"
ChangeNameToOtherName(ref name); // After method call name is "OtherName"

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com