Created
March 13, 2012 17:05
-
-
Save phillipkregg/2029944 to your computer and use it in GitHub Desktop.
C# Reverse String - First attempt at a class and method to reverse a string in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace MyLibrary | |
{ | |
public class StringReverse | |
{ | |
public string Reverse(string toBeReversed) | |
{ | |
// String reversal code | |
string incoming = toBeReversed; | |
List<char> reverseList = new List<char>(); | |
string[] reversedName; | |
for (int i = incoming.Length - 1; i >= 0; i--) | |
{ | |
Console.WriteLine(incoming[i]); | |
reverseList.Add(incoming[i]); | |
Console.WriteLine(reverseList.Cast<string>()); | |
} | |
reversedName = reverseList.Select(x => x.ToString()).ToArray(); | |
string result = string.Join("", reversedName); | |
return result; | |
// End string reversal | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment