Introduction
- In this blog, I am to show how to reverse a string without using length property in c#
Programming
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReverseString
{
class Program
{
static void Main(string[] args)
{
string reverseString = string.Empty;
Console.WriteLine("enter the string to reverse");
reverseString = Console.ReadLine();
int stringLength = 0;
foreach(var ch in reverseString)
{
stringLength++;
}
for (int i = stringLength-1; i >=0 ;i-- )
{
Console.Write(reverseString[i]);
}
Console.ReadLine();
}
}
}
Output: enter the string to reverse,
Nazartvm
Nazartvm
mvtrazaN
