我知道您可以在方法中传递对 struct
的引用,例如
void method(ref MyStruct param)
但是我可以在方法主体中为结构起别名以提高可读性吗?我有使用这个临时变量的代码:
var properties = this.document.header.protocols[0].properties;
只有在尝试跟踪错误时我才意识到这是因为它是结构而不是类,而且我创建的是副本而不是引用!
最佳答案
是的,starting with C# 7.0 , ref locals支持:
ref var properties = ref this.document.header.protocols[0].properties;
关于c# - 我可以在方法主体中创建对结构实例的临时引用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61634826/