In many of interviews, interviewers will ask write a program to reverse a string without using any built function. So in this snippet we will see how to reverse a string easily without using any built function or string function.
class StringReverseProgram
{static void Main(string[] args)
{
string normalStr = "This is DotNetMirror";
string reverseStr = string.Empty;
foreach (char chr in normalStr)
{
reverseStr = chr + reverseStr;
}
Console.WriteLine(reverseStr); //Output : rorriMteNtoD si sihT
Console.ReadKey();
}
}
Output:
rorriMteNtoD si sihT
0 Comments:
Post a Comment