美文网首页
Type Safer

Type Safer

作者: 津涵 | 来源:发表于2019-02-13 11:52 被阅读0次

    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

    相关文章

      网友评论

          本文标题:Type Safer

          本文链接:https://www.haomeiwen.com/subject/plwreqtx.html