HI WELCOME TO SIRIS

Reverse characters in a string

Leave a Comment
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 in StringCharacters)            {                Console.Write(c);            }

            Console.WriteLine();            Console.ReadLine();        }    }}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.