How to use enum in Solidity programming langauge ?

How to use enum in Solidity programming langauge ?


pragma solidity ^0.5.0;


contract test {

   enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }

   FreshJuiceSize choice;

   FreshJuiceSize constant defaultChoice = FreshJuiceSize.MEDIUM;


   function setLarge() public {

      choice = FreshJuiceSize.LARGE;

   }

   function getChoice() public view returns (FreshJuiceSize) {

      return choice;

   }

   function getDefaultChoice() public pure returns (uint) {

      return uint(defaultChoice);

   }

}

Comments

Last 7 Days

Smart contract code for Anyone can send coins to each other without a need for registering with a username and password with help of Ethereum keypair

How to use referrerpolicy Attribute value ( no-referrer-when-downgrade ) with < iframe > tag in HTML ? with example

How Artificial Intelligence Is Changing the World: A Complete Pro Guide

How Text Conversion Tools Work and Why They Are Useful

Why Convert PDF to Text and How It Helps in Editing & Research

How to use comments in Solidity programming language ?

How Text to Binary Converter – Convert Text into Binary Code work Online