-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
18_Enums.sol
32 lines (25 loc) · 863 Bytes
/
18_Enums.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Enums{
// Enums restrict a variable to have one of only a few predefined values.
// The values in this enumerated list are called enums.
// Enums require at least one member, and its default value when declared is the first member.
// Enums cannot have more than 256 members.
enum Size{
ExtraSmall,
Small,
Medium,
Large,
ExtraLarge
}
Size public size; // defaults value to 0
// Find the smallest and largest value of Enum Size
Size public smallestValue = type(Size).min; // 0
Size public largestValue = type(Size).max; // 4
function getValue() external view returns (Size){
return size; // Will return the default value 0
}
function setCurrentValue(Size _s) external{
size = _s; // Will set the value to the uint that is passed
}
}