Reverse logic for string

If we pass the ref type of string as a parameter.
It will the method reverseString will reverse your string
The below code is used to reverse your string

public void reverseString(ref string MyString) {
string tempStr = "";
int i, j;

Console.WriteLine("Reversing your string");
for(j=0, i=MyString.Length-1; i >= 0; i--, j++)
tempStr += MyString[i];

MyString = tempStr;

Code Explanation

1. Pass the ref type string as a parameter
2. create the variables tempstr,i,j
3. use the for loop logic as above you can get the reversed string as out put



Author: Fool To Code24 Oct 2009 Member Level: Gold   Points : 1

yes its a good logic and in we can use the vb inbuilt function:


it will show: kapeed


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: