C#如何保存big big int?

Wes*_*ron -6 c# int biginteger

我需要从字符串转换此值:4248035245857302861304475122262852382232831183377907185400973044372526725256648804647567360并将其保存在int中.长,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.");
                }
            }
Run Code Online (Sandbox Code Playgroud)

输入: 4248035245857302861304475122262852382232831183377907185400973044372526725256648804647567360

输出:

This is leap year. This is huluculu festival year. This is bulukulu festival year.

Zor*_*vat 6

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

string data = "927349273497234...";
BigInteger big = BigInteger.Parse(data);
byte[] serialized = big.ToByteArray();
Run Code Online (Sandbox Code Playgroud)

现在,您可以使用此字节数组将其保存到数据库或发送它.

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

byte[] data = ...
BigInteger later = new BigInteger(data);
Run Code Online (Sandbox Code Playgroud)