diff --git a/exercises/practice/reverse-string/.approaches/span/content.md b/exercises/practice/reverse-string/.approaches/span/content.md index 481116a9e8..f351f16591 100644 --- a/exercises/practice/reverse-string/.approaches/span/content.md +++ b/exercises/practice/reverse-string/.approaches/span/content.md @@ -1,12 +1,20 @@ # Span<T> ```csharp -Span chars = stackalloc[input.Length]; -for (var i = 0; i < input.Length; i++) +public static class ReverseString { - chars[input.Length - 1 - i] = input[i]; + public static string Reverse(string input) + { + Span chars = stackalloc[input.Length]; + + for (var i = 0; i < input.Length; i++) + { + chars[input.Length - 1 - i] = input[i]; + } + + return new string(chars); + } } -return new string(chars); ``` C# 7.2. introduced the [`Span`][span-t] class, which was specifically designed to allow performant iteration/mutation of _array-like_ objects.