Type Safer

BigInteger

BigInteger is a struct that contains a number of any size. You can initialize it from smaller types, pass a number array to create one big number, or parse a string for a huge number. This type implements methods for mathematical calculations. The namespace for BigInteger is System.Numeric.
BigInteger是一个包含任意大小的数字的结构体,您可以从较小的类型初始化它,传递一个数字数组来创建一个大数,或者解析一个字符串来生成一个大数。BigInteger的命名空间是System.Numeric

显示强制类型转换

(1) However, there are limitations on what you can do with explicit type conversions—as far as value types are concerned, you can only convert to and from the numeric and char types and enum types. You cannot directly cast Booleans to any other type or vice versa.
就值类型而言,只能转换为数值类型、字符类型和枚举类型。
不能直接将布尔值转换为任何其他类型,反之亦然。

(2)数值类型转换为string
If you need to convert between numeric and string, you can use methods provided in the .NET class library. The Object class implements a ToString method, which has been overridden in all the .NET predefined types and which returns a string representation of the object.
coding:
int i = 10;
string s = i.ToString();

(3)string转换为数值类型
Similarly, if you need to parse a string to retrieve a numeric or Boolean value, you can use the Parse method supported by all the predefined value types:
coding:
string s = "100";
int i = int.Parse(s);
Console.WriteLine(i + 50); // Add 50 to prove it is really an int

类型转换

coding:
int i = 3;
long l = i; // implicit
short s = (short)i; // explicit

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,151评论 0 10
  • 每一天,我走过城市的大街小巷。看到街上走过的行人,着装得体,一丝不苟,脸上洋溢着自信的笑容,浑身散发着感染人的热情...
    逸魂阅读 1,378评论 1 0
  • 理想 它是个迷人东西 一直被它勾引 比帅哥更让我着迷 为了它 甘愿经受 颠沛流离 为了它 甘愿倾尽 年华与精力 换...
    雪莉诗话阅读 1,267评论 0 5
  • 因为害怕忘记,所以自己慢慢地随着年纪不断增加或减少着日记字数,但不变的是一直希望自己能将生活铭记于心,不断去增...
    滴水铭心阅读 984评论 0 0
  • Carmen康康阅读 1,124评论 0 0