编译器错误 CS0199
更新:2007 年 11 月
错误消息
无法向静态只读字段“name”的字段传递 ref 或 out 参数(静态构造函数中除外)
在构造函数中作为 ref 或 out 参数传递的 readonly 变量,必须具有与构造函数相同的 static 用法。有关更多信息,请参见传递参数(C# 编程指南)。
示例
下面的示例生成 CS0199:
// CS0199.cs
class MyClass
{
public static readonly int TestInt = 6;
static void TestMethod(ref int testInt)
{
testInt = 0;
}
MyClass()
{
TestMethod(ref TestInt); // CS0199, TestInt is static
}
public static void Main()
{
}
}