In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you an analysis of how to carry out struct. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Struct syntax
Struct is similar to the encapsulation of an object property. For example, a student may have attributes such as name, student number and so on. These attributes are encapsulated to form a structure.
one
two
three
four
Struct object name {
Variable type 1 variable name 1
Variable type 2 variable name 2
}
The struct declaration defines a student class 1
two
three
four
Struct student {
Uint grade
String name
}
Structure cannot contain itself 1
two
three
four
five
Struct student {
Uint grade
String name
/ / student s; structure cannot contain itself
}
Structures can be nested
One structure can contain another structure inside.
one
two
three
four
five
six
seven
eight
nine
ten
Struct student {
Uint grade
String name
}
Struct student2 {
Uint grade
String name
Student ss; / / contains another structure
}
The structure can contain its own dynamic array 1
two
three
four
five
Struct student3 {
Uint grade
String name
The student3 [] stu;// structure can contain its own dynamic array
}
The structure can contain its own mapping mapping. one
two
three
four
five
Struct student4 {
Uint grade
String name
Mapping (uint= > student4) studentMap
}
Struct instantiation
There are several ways to define a structure
one
two
three
four
five
six
seven
eight
nine
Struct student {
Uint grade
String name
}
/ / method 1. Assign 100s and "jackson" to student in order.
Student (100, "jackson")
/ / method 2. Assign values by name
Student ({name: "jackson", grade:100})
Complete Code 1
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
forty-three
forty-four
forty-five
forty-six
forty-seven
Pragma solidity ^ 0.4.23
Contract structTest {
Struct student {
Uint grade
String name
/ / student s
}
Struct student2 {
Uint grade
String name
Student ss
}
Struct student3 {
Uint grade
String name
Student ss
Student3 [] stu
}
Struct student4 {
Uint grade
String name
Student ss
Student3 [] stu
Mapping (uint= > student4) studentMap
}
Function init () public pure returns (uint,string) {
Student memory s = student (100, "jackson")
Student3 [3] memory stu
Return (s.grade.name)
}
Function init2 () public pure returns (uint,string) {
Student memory s = student ({name: "jackson", grade:100})
Return (s.grade.name)
}
}
The above is the editor for you to share how to analyze struct, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.