Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何保存大整数?_C#_Int_Biginteger - Fatal编程技术网

C# 如何保存大整数?

C# 如何保存大整数?,c#,int,biginteger,C#,Int,Biginteger,我需要从字符串转换此值:42480324585730286130447512226285238223283118333779071854009730443725267252566488046447567360并将其保存为int.Long,Int64数据类型不起作用。我不能使用BigInteger。双不可分。有什么建议吗 string valorLido; while ((valorLido = Console.ReadLine()) !=

我需要从字符串转换此值:42480324585730286130447512226285238223283118333779071854009730443725267252566488046447567360并将其保存为int.Long,Int64数据类型不起作用。我不能使用BigInteger。双不可分。有什么建议吗

    string valorLido;            
            while ((valorLido = Console.ReadLine()) != null)
            {
                int leapYear = 0;
                int huluculuFestival = 0;
                int bulukuluFestival = 0;

                long ano = long.Parse(valorLido); 

                if ((ano % 4 == 0) && (ano % 100 != 0 || ano % 400 == 0))
                    leapYear = 1;
                if (ano % 15 == 0)
                    huluculuFestival = 1;
                if (leapYear == 1 && ano % 55 == 0)
                    bulukuluFestival = 1;

                if(leapYear == 1)
                    Console.WriteLine("This is leap year.");
                if(huluculuFestival == 1)
                    Console.WriteLine("This is huluculu festival year.");
                if(bulukuluFestival == 1)
                    Console.WriteLine("This is bulukulu festival year.");
                if((leapYear != 1) && (huluculuFestival != 1) && (bulukuluFestival != 1)) 
                {
                    Console.WriteLine("This is an ordinary year.");
                }
            }
输入: 424803245857302861304475122262852382232831183779071854009730443725267252566488046475567360

输出:

这是闰年。 今年是胡鲁古鲁节。
今年是布鲁库鲁节。

若您需要以可重用的方式表示大整数数据,例如,要将其保存在数据库中,您可以将其保留为字符串形式,也可以将其序列化为字节数组

string data = "927349273497234...";
BigInteger big = BigInteger.Parse(data);
byte[] serialized = big.ToByteArray();
现在您可以使用这个字节数组将其保存到数据库或发送给其他用户

稍后,您可以使用接收字节数组的构造函数重新创建BigInteger对象:

byte[] data = ...
BigInteger later = new BigInteger(data);

即使是乌龙也无法储存。您需要一个大整数。保存大整数意味着什么?您将对这些数字执行什么操作?打印它们?添加它们?从i循环到那个号码?你为什么不能用BigInteger@ADyson我使用在线判断URI,不能使用BigInteger,因为我得到了一些编译错误,可能网站不能使用.NET4.0引用。