The following code compiles successfully:
using System;
ref struct Example
{
public Span<byte> Field = stackalloc byte[512];
public Span<byte> Property { get; } = stackalloc byte[512];
public Example() {}
}
(SharpLab)
Neither the field nor the property are valid to access, as they are referencing stack memory from the constructor. Since this construct is wholly unsafe, it should probably be disallowed or at least warned.
The following code compiles successfully:
(SharpLab)
Neither the field nor the property are valid to access, as they are referencing stack memory from the constructor. Since this construct is wholly unsafe, it should probably be disallowed or at least warned.