In C++ you can separate the digits for readability in your code with apostrophes:
int num = 1'000'000;
In Ruby, you can use underscores:
num = 1_000_000
Is there a similar syntax for C#? I tried a few different searches but only came up with results for outputting or reading numbers in a particular format.
toCharArray() to Get the Array of Characters. Another way of separating the digits from an int number is using the toCharArray() method. We will convert the integer number into a string and then use the string's toCharArray() to get the characters' array. Now we can print out all the characters one by one.
Extracting digits of a number is very simple. When you divide a number by 10, the remainder is the digit in the unit's place. You got your digit, now if you perform integer division on the number by 10, it will truncate the number by removing the digit you just extracted.
As of the time this answer is written, that feature does not exist in C#. However, there is a feature request for it, and it looks like it will be part of C# 7, which is the upcoming version.
The feature request is listed on their C# 7 list of features, but you probably shouldn't assume 100% it will make it in. Things are subject to change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With