Skip to content

Why i cannot declaring stackalloc MyStr[10] when MyStr is 'ref struct' #94801

Answered by gfoidl
P9avel asked this question in General
Discussion options

You must be logged in to vote

Because MyStr is used as type argument for T in Span<T>, and ref structs are not allowed as type arguments.

You could

  • MyStr* a = stackalloc MyStr[10];
  • use [InlineArray] (.NET 8)

to work around this.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by P9avel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants