Mid From PDF Coding Scenarios C# Coding Interview

Reverse a string (without built-in reverse)?

Logic

  • Convert to char array.
  • Swap characters from both ends.
string str = "dotnet";
char[] chars = str.ToCharArray();
int left = 0, right = chars.Length - 1;

while (left < right)

{
char temp = chars[left];
chars[left] = chars[right];
chars[right] = temp;

left++;

right--;

}
string reversed = new string(chars);

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details