Created
July 13, 2022 10:25
-
-
Save ashwinYardi/4a9815b14d9a455297f618081a8d8939 to your computer and use it in GitHub Desktop.
Contract to demo value typed datatypes in solidity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solidity program to demonstrate | |
// value types | |
pragma solidity ^ 0.8.5; | |
// Creating a contract | |
contract DemoValueTypes { | |
// Initializing Bool variable | |
bool public boolean; | |
// Initializing Integer variable | |
int32 public intVar = -60313; | |
// Initializing String variable | |
string public str = "This is the sample string"; | |
// Initializing Byte variable | |
bytes1 public b = "a"; | |
// Defining an enumerator | |
enum sampleEnum { first, second, third, defaultValue } | |
// Defining a function to return values stored in an ENUM | |
function accessEnum(uint8 index) public pure returns( | |
sampleEnum) { | |
if (index == 0) { | |
return sampleEnum.first; | |
} else if (index == 1) { | |
return sampleEnum.second; | |
} else if (index == 2) { | |
return sampleEnum.third; | |
} else { | |
return sampleEnum.defaultValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment