Octal equivalent in C#

前端 未结 5 931
名媛妹妹
名媛妹妹 2020-12-16 08:56

In C language octal number can be written by placing 0 before number e.g.

 int i = 012; // Equals 10 in decimal.

I found the e

相关标签:
5条回答
  • 2020-12-16 09:39

    You can't use literals, but you can parse an octal number: Convert.ToInt32("12", 8).

    0 讨论(0)
  • 2020-12-16 09:41

    No there isn't, the language specification (ECMA-334) is quite specific.

    4th edition, page 72

    9.4.4.2 Integer literals

    Integer literals are used to write values of types int, uint, long, and ulong. Integer literals have two possible forms: decimal and hexadecimal.

    No octal form.

    0 讨论(0)
  • 2020-12-16 09:46

    No, there are no octal literals in C#.

    If necessary, you could pass a string and a base to Convert.ToInt32, but it's obviously nowhere near as nice as a literal:

    int i = Convert.ToInt32("12", 8);
    
    0 讨论(0)
  • 2020-12-16 09:47

    No, there are no octal number literals in C#.

    For strings: Convert.ToInt32("12", 8) returns 10.

    0 讨论(0)
  • 2020-12-16 09:49

    No, there are no octal numbers in C#.

    Use public static int ToInt32(string value, int fromBase);

    fromBase
    Type: System.Int32
    The base of the number in value, which must be 2, 8, 10, or 16.
    

    MSDN

    0 讨论(0)
提交回复
热议问题