C#读取一个整数Int方法
封装一个静态方法ReadInt()
static int ReadInt()
{
int res = 0;
int c;
do
{
c = Console.Read();
if (c >= 48 && c <= 57) res = res * 10 + c-48;
} while (c != 10 && c != 32);
return res;
}
eg
using System;
namespace TempNamespace
{
class TempClass
{
static int ReadInt()
{
int res = 0;
int c;
do
{
c = Console.Read();
if (c >= 48 && c <= 57) res = res * 10 + c-48;
} while (c != 10 && c != 32);
return res;
}
static void Main(string[] args)
{
int a = ReadInt();
Console.WriteLine(a);
}
}
}