How is the BigInteger structure in System.Numerics?
Why can I assign a literal to it, make an increment, add two structures through '+'?

    1 answer 1

    Because in the code of this structure, the increment / decrement operators, arithmetic and logical operators, as well as the operators of explicit and implicit reduction to basic numeric types (which allows us to assign numeric literals to it) are overloaded.

    Here, for example, how operator + is overloaded there:

    public static BigInteger operator +(BigInteger left, BigInteger right) { left.AssertValid(); right.AssertValid(); if (right.IsZero) return left; if (left.IsZero) return right; int sign1 = +1; int sign2 = +1; BigIntegerBuilder reg1 = new BigIntegerBuilder(left, ref sign1); BigIntegerBuilder reg2 = new BigIntegerBuilder(right, ref sign2); if (sign1 == sign2) reg1.Add(ref reg2); else reg1.Sub(ref sign1, ref reg2); return reg1.GetInteger(sign1); } 

    Thanks to this overload, you can add two BigInteger using the usual + operator, and not write your own Add methods for it (hello, java).

    Everything else, if you're interested, you can read here.