Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Jul 10, 2025, 1:10 AM EDT
using System; class Program { static void Main() { Console.Write("Enter a string to reverse: "); string input = Console.ReadLine(); string reversed = ReverseString(input); Console.WriteLine($"Reversed string: {reversed}"); } static string ReverseString(string str) { char[] charArray = str.ToCharArray(); // Convert to character array Array.Reverse(charArray); // Reverse the array return new string(charArray); // Create a new string from the reversed array } }Praveen KumarRank #4 · 79.9K reputationPosted Jul 10, 2025, 4:01 AM EDT
C# Corner forums are here to help you learn and grow as a developer. Instead of asking for a complete solution like ‘Write a program to reverse a string,’ we encourage you to try writing some code yourself first. Share what you’ve attempted, and we’ll be happy to guide you from there!
Cynthia SathuragiriRank #937 · 2.2K reputationPosted Jul 10, 2025, 2:33 AM EDT
We can use LINQ's Reverse() to reverse the characters. Here we can code a method in just a few lines
class Program
{
static void Main()
{
Console.Write("Enter a string: ");
string input = Console.ReadLine();
Console.WriteLine("Reversed string: " + new string(input.Reverse().ToArray()));
}
}
Ajay BansodeRank #7,443 · 241 reputationPosted Jul 13, 2025, 1:59 AM EDT
Manual Reversal Logic:
using System;
class Program
{
static void Main()
{
Console.Write("Enter a string to reverse: ");
string input = Console.ReadLine();
string reversed = ReverseString(input);
Console.WriteLine("Reversed string: " + reversed);
}
static string ReverseString(string str)
{
string result = "";
for (int i = str.Length - 1; i >= 0; i--)
{
result += str[i]; // Append characters from end to start
}
return result;
}
}
Sandhiya PriyaRank #26 · 43.2K reputationPosted Jan 2, 2026, 11:08 PM EST
Here’s a simple C# program that reverses a string:
using System; class Program { static void Main() { // Input string Console.Write("Enter a string: "); string input = Console.ReadLine(); // Reverse the string using built-in methods char[] charArray = input.ToCharArray(); Array.Reverse(charArray); string reversed = new string(charArray); // Output the reversed string Console.WriteLine("Reversed string: " + reversed); } }Explanation:
Console.ReadLine()? Reads user input.ToCharArray()? Converts the string into a character array.Array.Reverse()? Reverses the array in place.new string(charArray)? Creates a new string from the reversed array.Example Run:
Priya PrajapatiRank #1,224 · 1.5K reputationPosted Jan 4, 2026, 3:18 AM EST
Here is C# program for reverse a string without using reverse method.
StephenKirk14 reputationPosted Jan 5, 2026, 10:01 PM EST
How can I do this task?