cathei
Using stackalloc span in if statement
For example you might
return entry;
that ends up exposing invalid value outside of the method. scoped
local introduced to ensure that the variable will not escape current scope. I believe it is also partially backward-compatibility reason involved that we need to explicitly put keyword for it.5 replies
Using stackalloc span in if statement
From my understanding compiler is complaining because it is worried about
entry
escaping outside of its valid context. You may add scoped
keyword to entry
(scoped ReadOnlySpan<char> entry
) to make it scoped local to make compiler happy. It should also work if MemoryExtensions.TrimEnd
took scoped trimChars
, but seems like that is not what we have today.
This can be a good reading: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/low-level-struct-improvements#scoped-locals
Some language folks might chime in and add some details too :catcomf:5 replies