You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when you take a row span from the Span2D you're working with by calling mySpan2D.GetRowSpan(rowNumber) and, say, you wish to know the index of 'S', the compiler will tell you you need to use a variable because it is passed to a ref readonly parameter. The using statement using CommunityToolkit.HighPerformance at the top of the file will make the compiler ignore all the methods in MemoryExtensions if they have the same name. So I ended up scratching my head, "Didn't I use this before with the same parameter and it worked just fine?").
The last approach works for everything that's shadowing its MemoryExtensions cousin, I think. But it took me a while to figure out, perhaps because I haven't been programming for very long and not that used to working with Span yet (that was the first ref readonly parameter I ever saw).
The most elegant approach is definitely the static using statement but I only figured that out while writing this post. I had assumed it would make the calls ambiguous but that's not the case so perhaps that could be mentioned in the documentation or in the tooltip?
An overload to the MemoryExtensions method would work as well but I suppose it's a bit awkward that the high performance method calls the regular method...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently when you take a row span from the Span2D you're working with by calling
mySpan2D.GetRowSpan(rowNumber)
and, say, you wish to know the index of 'S', the compiler will tell you you need to use a variable because it is passed to a ref readonly parameter. The using statementusing CommunityToolkit.HighPerformance
at the top of the file will make the compiler ignore all the methods in MemoryExtensions if they have the same name. So I ended up scratching my head, "Didn't I use this before with the same parameter and it worked just fine?").So you could wrap everything in spans beforehand:
You could write the MemoryExtensions extension method in full.
You could use a static using statement to the base library
Or wrap the value within the call itself
The last approach works for everything that's shadowing its MemoryExtensions cousin, I think. But it took me a while to figure out, perhaps because I haven't been programming for very long and not that used to working with Span yet (that was the first ref readonly parameter I ever saw).
The most elegant approach is definitely the static using statement but I only figured that out while writing this post. I had assumed it would make the calls ambiguous but that's not the case so perhaps that could be mentioned in the documentation or in the tooltip?
An overload to the MemoryExtensions method would work as well but I suppose it's a bit awkward that the high performance method calls the regular method...
Beta Was this translation helpful? Give feedback.
All reactions