c#程序控制台一个整数。在逆序输出!如123,输出则是321!写的越简单越好,一看就懂
c#程序控制台一个整数。在逆序输出!如123,输出则是321!写的越简单越好,一看就懂

程序代码:using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
int a = 1234567;
char[] b = a.ToString().ToCharArray();
Array.Reverse(b);
string c = new string(b);
Console.WriteLine(c);
}
}
如果不知道Array.Reverse()的用法,那么还可以这么做
程序代码:using System;
class Program
{
static void Main(string[] args)
{
int a = 1234567;
char[] b = a.ToString().ToCharArray();
int c = b.Length / 2;
for (int i = 0; i < c; i++)
{
char tmp = b[i];
int d = b.Length - i - 1;
b[i] = b[d];
b[d] = tmp;
}
string e = new string(b);
Console.WriteLine(e);
}
}
