Discussion: Span of ref struct? #2816
Replies: 4 comments
-
This would have to require something like #1148. |
Beta Was this translation helpful? Give feedback.
-
It's more than that. How should the compiler know that you cannot pass your public class C
{
object remember;
public bool Test<T>(Span<T> s)
{
remember = s.ToArray();
return true;
}
} |
Beta Was this translation helpful? Give feedback.
-
@quinmars, exactly as I said. A[] arr = stackalloc A[10];
var arr = stackalloc A[10]; //this will be interpreted as A[] - valid in the safe context P.S. A[] is not the default array here, this is just an example, syntax may differ. |
Beta Was this translation helpful? Give feedback.
-
@HanabishiRecca Span is available on .NET Framework 4.5 and higher with a NuGet package, as well as Mono, Xamarin, UWP, and PCLs. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Why we can't declare Span of ref struct?
Span itself is already a ref struct. So, if manually created ref struct of ref structs is ok, why we can't use Span of ref struct?
Of course ref struct can't be used as a generic type, but this is just a formal restriction. This means Span just needs some workaround.
E.g. such thing is possible in the unsafe context
We need something similar in the safe context.
Beta Was this translation helpful? Give feedback.
All reactions