braceless with statements

Ali Çehreli acehreli at yahoo.com
Fri Nov 12 20:52:22 UTC 2021


On 11/12/21 11:47 AM, Dr Machine Code wrote:

>> Or enums. Enums. ENUMS!!! :)
> 
> what's wrong with them?

They are great. :) 'with' helps especially with switch statements:

enum LongEnumName {
   a, b, c
}

void main() {
   LongEnumName e;

   // 'LongEnumName.' is repeated for each case:
   final switch (e) {
   case LongEnumName.a:
   case LongEnumName.b:
   case LongEnumName.c:
   }

   // Same thing but shorter syntax:
   final switch (e) with (LongEnumName) {
   case a:
   case b:
   case c:
   }
}

Ali


More information about the Digitalmars-d mailing list