【发布时间】:2023-04-06 10:29:01
【问题描述】:
是否可以通过引用分配?我知道 ref 必须在方法中使用。
string A = "abc";
string B = A;
B = "abcd";
Console.WriteLine(A); // abc
Console.WriteLine(B); // abcd
可以给我一些吗
string A = "abc";
string B = (ref)A;
B = "abcd"; // A was assigned to B as reference, so changing B is the same as changing A
Console.WriteLine(A); // abcd
Console.WriteLine(B); // abcd
【问题讨论】:
-
@Tudor 我认为他期望将“abcd”的值分配给 A。
标签: c#