Learn Ethereum Solidity by Sathish Janani

Learn Ethereum Solidity by Sathish Janani

Author:Sathish, Janani
Language: eng
Format: epub, pdf
Published: 2021-08-18T16:00:00+00:00


ENUMS

We are going to cover ENMs I, you know, is a enumerated type. It allows you to quit your own data type and assign names to essentially integer values, a sicker sequential set of integer values. So it's a great way. If, for example, you have some information and you're, and the information is.

Just going up like 0 1, 2, 3, 4 5 6, 7, 8, 9, 10, for example, instead of creating 10 different variables for it. Cause you want to, you know, use that, those numbers again and again, and you just want some sort of name to be some sort of common name they can easily just look at and refer to. He use a E and M to create an email.

Very simple. Just do E numb, like so, and I'll just call it special type. You know, they stopped. This is the name of the inner and open curly braces. And here you just put numbers. I mean, names. So I'm just going to put 1, 2, 3, 4. So there's total of five in here. You could have one, you could have five for 20, could have 30 COVID as many as you want.

So let me just show you something. To actually use it, even though they're essentially numbers, they can't be explained. They can't explicitly be converted to a integer or sign integer on like other programming languages allow you to. So if you wanted to return a special type, okay, this type here, you would change this to special type because that's the data type.

And that was produced. That short type let's say for return one, what will we get so far? Click create, get we get zero my thinking. Okay. Yeah. The return. Anything left you up in the free return to, and I will click create gap is return lawns. So let me try and what do you think. I've got an idea in my head.

Hopefully I'm right. Get full. Remember in computers, pretty much everything starts from zero instead of one. So 0 1, 2, 3, 4, 5. So this first value here is zero. This is one. This is two. If you're free and this is for, so again, like I said, it's just a sequential set of integer values or equivalent of you.

Can't assign this to let's say integer variable, but what you can do is create essay a special type of variable. So we'll call is involve one and involve one. I could assign something to say for Deval one. Equals maybe. Yeah. Well, one that's a doc. Do the, yeah, I could do one equals special type dot four, for example.

And I could just print over one here. So I've been doing well. One. So now, if I were to delete all his old contracts, click create, I click get, he just puts zero because nothing's been assigned to it for click set and then click get it gets free. Cause remember 0 1, 2. So that's it for enumerated types.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.