Skip to content

Enumerations

NN--- edited this page Mar 22, 2012 · 3 revisions

Enumerations

  • Category: Defining Types

  • Description: Enums are lightweight types, similar to discriminated unions. Unlike discriminated unions, each data tag must be given a constant value of the same type

  • Code:

 using System; 
 using System.Console;

enum FaceCard 
{
    | Jack  = 11
    | Queen = 12
    | King  = 13
    | Ace   = 1
}

def EnumSample() 
{
    def isAce(card)
    {
        | FaceCard.Ace => true
        | _            => false
    }
             
    WriteLine($"Checking if a Jack is an Ace: $(isAce(FaceCard.Jack))")
}

EnumSample() 
  • Execution Result:
Checking if a Jack is an Ace: False 

[Copyright ©](Terms of use, legal notice)

Clone this wiki locally