gpt4 book ai didi

c# - 为什么字符串上的 Thread.VolatileRead 无法编译

转载 作者:行者123 更新时间:2023-11-30 17:59:03 24 4
gpt4 key购买 nike

class CFoo 
{
private string _filePathFormatString;

public string Foo()
{
System.Threading.Thread.VolatileRead(ref _filePathFormatString);
...
}
}

string 是对象,为什么这个 VolatileRead 不编译?我认为它应该匹配 VolatileRead(ref object) 签名。

最佳答案

如果在 C# 中使用“ref”传递参数,形式参数和实际参数的类型必须完全相同。因此,您可以将字段更改为对象类型。第二种方法可能是使用 ReaderWriteLockSlim而不是 volatile 读取。

关于c# - 为什么字符串上的 Thread.VolatileRead 无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11575907/

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