- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to reverse a string
Our sample string is −
myStr = "Tom";
To reverse the string, firstly find the length of the string −
// find string length int len; len = myStr.Length - 1;
Now, use a while loop until the length is greater than 0 −
while (len >= 0) { rev = rev + myStr[len]; len--; }
Example
You can try to run the following code to reverse a string in C#.
using System; class Demo { static void Main() { string myStr, rev; myStr = "Tom"; rev =""; Console.WriteLine("String is {0}", myStr); // find string length int len; len = myStr.Length - 1; while (len >= 0) { rev = rev + myStr[len]; len--; } Console.WriteLine("Reversed String is {0}", rev); Console.ReadLine(); } }
Output
String is Tom Reversed String is moT
- Related Articles
- C# program to Reverse words in a string
- Java Program to Reverse a String
- C# Program to display a string in reverse alphabetic order
- Write a Golang program to reverse a string
- Write a program to reverse an array or string in C++
- Java program to reverse a string using recursion
- Java Program to Reverse a String Using Stacks
- How to reverse a string in Python program?
- Python Program to Reverse a String Using Recursion
- Write program to reverse a String without using reverse() method in Java?
- Write a C program to Reverse a string without using a library function
- How to reverse a String using C#?
- Reverse a string in C#
- Reverse a String (Iterative) C++
- Reverse a String (Recursive) C++

Advertisements