Declaring a single const: enum vs const vs immutable

Brother Bill brotherbill at mail.com
Wed Sep 10 16:52:51 UTC 2025


Is there any reason to pick one of these vs. another one, or are 
they all equivalent?

If equivalent, it would seem that immutable appears to be the 
'strongest', whereas enum has fewer keystrokes.

Is there a D 'best practice' for this?

```
	const int foo1 = 42;
	enum foo2 = 42;
	immutable int foo3 = 42;

	const string str1 = "Any difference";
	enum str2 = "Any difference";
	immutable string str3 = "Any difference";

```


More information about the Digitalmars-d-learn mailing list