Compiler Error CS0842
Automatically implemented properties cannot be used inside a type marked with StructLayout(LayoutKind.Explicit).
Automatically implemented properties have their backing fields provided by the compiler and the field is not accessible to source code. Therefore, they are not compatible with LayoutKind.Explicit.
- Make the property a regular property in which you provide the accessor bodies.
The following example generates 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;
}
}
}
.NET maklum balas
.NET ialah projek sumber terbuka. Pilih pautan untuk memberikan maklum balas: