September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
6
Task/Reverse-a-string/C-sharp/reverse-a-string-1.cs
Normal file
6
Task/Reverse-a-string/C-sharp/reverse-a-string-1.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
static string ReverseString(string input)
|
||||
{
|
||||
char[] inputChars = input.ToCharArray();
|
||||
Array.Reverse(inputChars);
|
||||
return new string(inputChars);
|
||||
}
|
||||
7
Task/Reverse-a-string/C-sharp/reverse-a-string-2.cs
Normal file
7
Task/Reverse-a-string/C-sharp/reverse-a-string-2.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using System.Linq;
|
||||
|
||||
// ...
|
||||
|
||||
return new string(input.Reverse().ToArray());
|
||||
|
||||
// ...
|
||||
14
Task/Reverse-a-string/C-sharp/reverse-a-string-3.cs
Normal file
14
Task/Reverse-a-string/C-sharp/reverse-a-string-3.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
public string ReverseElements(string s)
|
||||
{
|
||||
// In .NET, a text element is series of code units that is displayed as one character, and so reversing the text
|
||||
// elements of the string correctly handles combining character sequences and surrogate pairs.
|
||||
var elements = System.Globalization.StringInfo.GetTextElementEnumerator(s);
|
||||
return string.Concat(AsEnumerable(elements).OfType<string>().Reverse());
|
||||
}
|
||||
|
||||
// Wraps an IEnumerator, allowing it to be used as an IEnumerable.
|
||||
public IEnumerable AsEnumerable(IEnumerator enumerator)
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
yield return enumerator.Current;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue