'Enum Solidity Understanding
I am trying to understand solidity bit better, however the underscores drive me crazy.
Let’s say I declare an enum
enum wine {red, white}
And now I declare a variable of type enum and I assign a value
wine _wine = wine.red
Why do I need there an underscore in front of the second wine?
Happy for comments!
Solution 1:[1]
You cannot have a variable with the same name as an already existing datatype.
Example from many other typed languages:
// ok
string _string = "hello";
// error - cannot have a `string` type variable called `string`
string string = "hello";
In your case, wine specifies the datatype, and _wine is the variable name.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Petr Hejda |
