Using pure c#
string StrInput ="PABITRA";
string StrReverse = "";
int Len = StrInput.Length - 1;
for (int i = Len; i>=0; i--)
StrReverse = StrReverse + StrInput[i];
//Console.Write(StrReverse);
//Console.ReadLine();
Response.Write(StrReverse);
OR
string StrInput ="PABITRA";
string StrReverse = "";
int Len = StrInput.Length - 1;
while (Len >= 0)
{
StrReverse = StrReverse + StrInput[Len]; Len--;
}
//Console.Write(StrReverse);
//Console.ReadLine();
Response.Write(StrReverse);
Using IEnumerable
IEnumerable<char> c = "pabitra".Reverse();
string rev = string.Empty;
foreach (var v in c)
{
if (rev == string.Empty)
rev = v + "\n";
else
rev = rev + v + "\n";
}
Console.Write(rev);
Console.ReadLine();
OR
Using Linq
string reverse = string.Join(" ", "pabitra".Split(' ').Select(x => new string(x.Reverse().ToArray())));
Console.Write(reverse);
Console.ReadLine();
No comments:
Post a Comment