Subscribe Now!

Enter your email address:

Friday, January 21, 2011

Example program that reverses strings (C#)


using System;

static class StringHelper
{
    /// <summary>
    /// Receives string and returns the string with its letters reversed.
    /// </summary>
    public static string ReverseString(string s)
    {
        char[] arr = s.ToCharArray();
        Array.Reverse(arr);
        return new string(arr);
    }
}

class Program
{
    static void Main()
    {
        Console.WriteLine(StringHelper.ReverseString("framework"));
        Console.WriteLine(StringHelper.ReverseString("samuel"));
        Console.WriteLine(StringHelper.ReverseString("example string"));
    }
}

=== Output of the program ===

krowemarf
leumas
gnirts elpmaxe

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...