、
想输入的字符串数据转为逆序的整数数组,不清楚错误怎么改(这是新建的类文件,主文件只是两个输入参数的语句)另外,a.后面为啥不显示一系列字符串方法?
switch是关键字(编辑器已经用蓝色标记出来提醒你了),关键字就不能用于命名函数、变量、类名等。
比如,你不能写 int int; 或者class new或者 float if()。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q714053
{
class Program
{
static int[] Str2ReverseArray(string a)
{
return a.Reverse().Select(x => x - '0').ToArray();
}
static void Main(string[] args)
{
string s = "1234";
int[] arr = Str2ReverseArray(s);
for (int i = 0; i < arr.Length; i++)
Console.WriteLine(arr[i]);
}
}
}
另外,已经有大数运算类了。
先添加下System.Numerics的引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace Q714053
{
class Program
{
static void Main(string[] args)
{
string s1 = "12345678901234567890";
string s2 = "121118888888800001111111111111111111111";
BigInteger b1 = BigInteger.Parse(s1);
BigInteger b2 = BigInteger.Parse(s2);
var r = BigInteger.Add(b1, b2);
Console.WriteLine(r.ToString());
}
}
}
121118888888800001123456790012345679001
Press any key to continue . . .