更新:2007 年 11 月
错误消息
不能在用 StructLayout(LayoutKind.Explicit) 标记的类型内部使用自动实现的属性。自动实现的属性具有由编译器提供的支持字段,此类字段不能由源代码访问。因此,这些属性与
更正此错误
使该属性成为提供访问器体的常规属性。
示例
下面的示例生成 CS0842:
// cs0842.cs
using System;
using System.Runtime.InteropServices;
namespace TestNamespace
{
[StructLayout(LayoutKind.Explicit)]
struct Str
{
public int Num // CS0842
{
get;
set;
}
static int Main()
{
return 1;
}
}
} | |