Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Created March 13, 2012 17:05
Show Gist options
  • Save phillipkregg/2029944 to your computer and use it in GitHub Desktop.
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#
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