I have read a few articles about how Span can be used to replace certain string operations. As such I have updated some code in my code base to use this new feature, however, to be able to use it in-place I then have to call .ToString()
.
Does the .ToString()
effectively negate the benefit I get from using Span<T>
rather than Substring
as this would have to allocate memory? In which case how do I reap the benefits if Span in this way, or is it just not possible?
//return geofenceNamesString.Substring(0, 50); Previous code
return geofenceNamesString.AsSpan().Slice(0, 50).ToString();
String
negates the benefit by allocating a string. You need to return aSpan<T>
– Puggree