15,562,561 members
See more:
Hi i want to know how can i contrariwise the number 4digit or 5digit
like this
1234
4321
546
645
With Respect
Posted
george4986 9-Oct-14 2:31am
u mean reverse?
Sinisa Hajnal 9-Oct-14 2:48am
Please do NOT post your questions here before doing some research. This is not free-code service!

## Solution 3

Again, simple google query "String.Reverse .net" will get you tons of solutions.

## Solution 1

You can do it this way

C#
```int i = 1234;
string s = i.ToString();                        // Convert the int to a string
string r = new string(s.Reverse().ToArray());   // Reverse the string
int j = int.Parse(r);                           // Convert the reversed string to an int```

Or the one liner
C#
`int k = int.Parse(new string(i.ToString().Reverse().ToArray()));`

## Solution 2

C#
```int n = 456;
int getnum= n;
int rev = 0;
while(getnum>0)
{
r = getnum% 10;
rev = rev * 10 + r;
left = getnum/ 10;  //left = Math.floor(left / 10);
}```

Avenger1 9-Oct-14 2:37am
what is "r" and "left"?
murkalkiran 9-Oct-14 2:39am
sorry left is getnum
r is int
Avenger1 9-Oct-14 2:55am
can you give me a fixed code because it just give me "0" result

Top Experts
Last 24hrsThis month
 Richard MacCutchan 155 CPallini 115 merano99 90 k5054 85 OriginalGriff 85
 Member 15908710 109 Richard MacCutchan 20 OriginalGriff 20 Karthika Ramachandran 2023 10 k5054 10

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900