C# Program to Reverse a String with Predefined Function

This is a C# Program to reverse a string with predefined function.

Problem Description

This C# Program Reverses a String with Predefined Function.

Problem Solution

Here the String is Reversed using the predefined Function reverse().

Program/Source Code

Here is source code of the C# Program to Reverse a String with Predefined Function. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

 * C# Program to Reverse a String with Predefined Function
using System;
class linSearch
    public static void Main()
        Console.WriteLine("Enter Number of Elements you Want to Hold in the Array? ");
        string s = Console.ReadLine();
        int x = Int32.Parse(s);
        int[] a = new int[x];
        Console.WriteLine("\n Enter Array Elements : ");
        for (int i = 0; i < x; i++)
            string s1 = Console.ReadLine();
            a[i] = Int32.Parse(s1);
        Console.WriteLine("Reversed Array : ");
        for (int i = 0; i < x; i++)
            Console.WriteLine("Element {0} is {1}", i + 1, a[i]);
Program Explanation

This C# program, we are reading the size of an array using ‘s’ variable. Using for loop we are entering the coefficient values of an array. The string is reversed using the predefined function reverse() by passing the value of ‘a’ variable as an argument. Another for loop is used to print the reverse of a string.

Runtime Test Cases
Enter Number of Elements you Want to Hold in the Array ? 5
Enter Array Elements : 2
Reversed Array :
Element is : 6
Element is : 5
Element is : 4
Element is : 3
Element is : 2

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.