BigInteger a = BigInteger.Parse("13454546656444999999999999999999999999999999999999999999999999999999");
a = BigInteger.Add(a,a);
这样不就改变了a的值吗?
c# 中为什么说BigInteger是不可变的呢?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
threenewbee 2016-08-13 02:22关注因为内部实现上,大概类似
BigInteger Add(a)
{
return new BigInteger(当前值+a);
}
而不是
BigInteger Add(a)
{
当前值+a;
return this;
}
因此一个BigInteger建立起来,这个对象的状态就不会变了。解决 无用评论 打赏 举报