Autore Topic: Enum: esempio di suo utilizzo  (Letto 288 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.305
  • Ne mors quidem nos iunget
    • Mostra profilo
Enum: esempio di suo utilizzo
« il: 15 Settembre 2013, 18:01:13 »
Riporto questa discussione apparsa nella Mailing List ufficiale relativamente alla parola chiave Enum, che, come riporta la guida in linea, dichiara un'enumerazione (o lista numerata, conteggio):


" Is there a selfexplaining, simpleand clear examplecode available using ENUM ?
The docs example are not sufficient for my weak head.

wally
"


" Really? You use Enum as a more convenient way to declare integer constants:

---

Codice: gambas [Seleziona]
' The file permission numerical constants
Private Const PERM_EXEC  As Integer = 1
Private Const PERM_WRITE As Integer = 2
Private Const PERM_READ     As Integer = 4


---

simply becomes

---

Codice: gambas [Seleziona]
Private Enum PERM_EXEC = 1, PERM_WRITE = 2, PERM_READ = 4


---

with the additional ability to have implicit sequences:

---

Codice: gambas [Seleziona]
' Counting
Private Const Zero As Integer = 0
Private Const One  As Integer = 1
Private Const Two  As Integer = 2


---

will be

---

Codice: gambas [Seleziona]
Private Enum Zero, One, Two


---

The first value, if not explicitely given, defaults to 0. The n+1-st value
becomes the n-th value plus 1.

Please, make your own example code of it if you want...

Regards,
Tobi
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »