Octal equivalent in C#

安稳与你 提交于 2019-11-29 02:48:27

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

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

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.

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);

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!