This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Me And My Respected Teacher Mr Kamal Sheel Mishra

Mr. K.S. Mishra is HOD of Computer Science from SMS Varanasi where I have completed my MCA

Me And My Respected Teacher Mr Udayan Maiti

Mr. Udayan Maiti is a senior .Net Expert and has guided many professionals of multi national Companies(MNC)

Me And My Best Friend Mr Ravinder Goel

Mr. Ravinder Goel is a senior Software Engineer and now he is working Wipro Technology

Friday 30 March 2018

String Reverse related questions in C# which is frequently ask in the interview



Q How to reverse a string in C# using predefined method ToCharArray()

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReverseStringConcept
{
class Program
{
static void Main(string[] args)
{
string strInput = null, strOutput = null;
Console.WriteLine("enter a string to revers");
strInput = Console.ReadLine();
char[] charInput = strInput.ToCharArray();
for (int i = charInput.Length-1; i >=0; i--)
{
strOutput = strOutput + strInput[i];
}
Console.WriteLine("reverse---->" + strOutput);
Console.ReadLine();
}
}
}
//ToCharaArray[]è
Copies the characters in this instance to a Unicode character array.
        //
        // Returns:
        //     A Unicode character array whose elements are the individual characters of
        //     this instance. If this instance is an empty string, the returned array is
        //     empty and has a zero length.


Q. How to reverse a string without any pre define function ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReverseStringConcept
{
class Program
{
static void Main(string[] args)
{
string strInput = null, strOutput = null;
int Length;
Console.WriteLine("enter a string to revers");
strInput = Console.ReadLine();
Length = strInput.Length - 1;
while (Length >= 0)
{
strOutput = strOutput + strInput[Length];
Length--;
}
Console.WriteLine("reverse   -->" + strOutput);
Console.ReadLine();
}
}




Output


Q Find given String is a palindrom or not?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
            
namespace ReverseStringConcept
{
class Program
{
static void Main(string[] args)
{
string strInput = null, strOutput = null;

Console.WriteLine("enter a string to ");
strInput = Console.ReadLine();

char[] charInput = strInput.ToCharArray();
for (int i = charInput.Length- 1; i >= 0; i--)
{
strOutput = strOutput + charInput[i];
}

//Console.WriteLine(strInput);
//Console.WriteLine(strOutput);
if (strOutput == strInput)
{
Console.WriteLine("palindrom");

}
else
{
Console.WriteLine("Not a palindrom");

}

Console.ReadLine();
}
}
}
Output:





Q. Reverse  the string words  in the same position

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReverseStringConcept
{
class Program
{
static void Main(string[] args)
{
string strInput = null, strOutput = null;
Console.WriteLine("enter a string to ");
strInput = Console.ReadLine();
string[] words = strInput.Split(' ');

for (int i = 0; i <= words.Length-1; i++)
{
char[] charInput = words[i].ToCharArray();
for (int j = charInput.Length-1; j >=0; j--)
{
strOutput = strOutput + charInput[j];
}
strOutput += " ";

}
Console.WriteLine("reverse---->" + strOutput);
Console.ReadLine();
}
}
}
Output: