MVC ASP.NET C# SQL Server WCF Written Test HR Round Subscribe C# Videos C# Programs Buy DVD

Reverse characters in a string

Write a C# program to print the characters in a string in the reverse order.

using System;
using System.Collections.Generic;
using System.Linq;

namespace SamplePrograms
    class ReverseCharacters
        public static void Main()
            // Prompt the user to enter the string
            Console.WriteLine("Please enter your string");

            // Read the user string from console
            string UserString = Console.ReadLine();

            // The simple way to reverse a string is to use
            // the built-in .net framework Reverse() function
            List<char> StringCharacters = UserString.Reverse().ToList();
            // Finally print each character from the collection
            foreach (char c in StringCharacters)


1 comment:

  1. It's more favorable to create a StringBuilder and append to it each character StringCharacters