-
Notifications
You must be signed in to change notification settings - Fork 2
/
014-struct-in-solidity.sol
45 lines (38 loc) · 1.11 KB
/
014-struct-in-solidity.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
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* Working with structs in solidity
*
* Structs are types that are used to represent a record.
* Supposed you want to keep track of movies in a library
* You might want to keep track of the following
* properties about each movie:
*
* title, director, movieID
*/
contract LearnStructs {
// Defining a movie structure
struct Movie {
string title;
string director;
uint256 movieID;
}
// we can create many variables of type Movie
Movie movie;
Movie horrorMovies;
Movie scienceFictionMovies;
Movie commedyMovies;
// set a movie
function setMovie() public {
movie = Movie("The Contrast Pair", "TheUnicornDev", 1);
horrorMovies = Movie("Targetting TheTarget", "AbstractDev", 1);
}
// get the movie
function getMovieID() public view returns (uint256) {
return movie.movieID;
}
// wanna watch horror movie --lets get you what you want
function getHorrorMovieID() public view returns (uint256) {
return horrorMovies.movieID;
}
}