Can I declare constant integers with a thousands separator in C#?

Yes you can do this with C # 7.0 as shown here

public const long BillionsAndBillions = 100_000_000_000;

Answer as of C# 7

Yes, this is supported in C# 7. But be aware that there's no validation that you've put the underscores in the right place:

// At a glance, this may look like a billion, but we accidentally missed a 0.
int x = 1_00_000_000;

Answer from 2011

No, there's nothing like that in C#. You could do:

const int x = 1000 * 1000;

but that's about as nice as it gets.

(Note that this enhancement went into Java 7 as well... maybe one day it will be introduced in C#.)

Tags:

C#

Constants