How to use twoarray of solidity
This article mainly explains "how to use solidity's twoarray". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use solidity's twoarray.
Two-dimensional array definition 1
Uint [2] [3] grade = [60, 80], [40, 20], [50, 50]]
Returns the two-dimensional array 1
two
three
four
Function getGrade () view public returns (uint [2] [3]) {
Return grade
}
Get two-dimensional array length 1
two
three
four
five
six
seven
eight
nine
Function getLength () view public returns (uint) {
Return grade.length
}
Function getLength3 () view public returns (uint) {
Return grade [0] .length
}
Change content 1
two
three
four
five
six
seven
Function changeContent () public {
Grade [0] [1] = 100
/ / grade.push (ericGrade)
/ / grade [0] [2] = 90
}
Complete code demo 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
forty-eight
forty-nine
fifty
fifty-one
fifty-two
fifty-three
fifty-four
fifty-five
fifty-six
fifty-seven
fifty-eight
fifty-nine
sixty
sixty-one
sixty-two
sixty-three
sixty-four
sixty-five
sixty-six
sixty-seven
sixty-eight
sixty-nine
seventy
seventy-one
seventy-two
seventy-three
seventy-four
Pragma solidity ^ 0.4.23
Contract twoArray {
/ / uint [2] jonsongrade = [60BZ 80]
Uint [2] ericGrade = [40BZ 20]
/ / uint [2] stevenGrade = [50 ~ 50]
Uint [2] [3] grade = [60, 80], [40, 20], [50, 50]]
Function getGrade () view public returns (uint [2] [3]) {
Return grade
}
Function getLength () view public returns (uint) {
Return grade.length
}
Function getLength3 () view public returns (uint) {
Return grade [0] .length
}
/ / function changelength () public {
/ / grade [0] .length = 10
/ /}
Function changeContent () public {
Grade [0] [1] = 100
/ / grade.push (ericGrade)
/ / grade [0] [2] = 90
}
/ / get the content and sum
Function add () view public returns (uint) {
Uint sum = 0
/ / there are some differences between defining and obtaining data. When obtaining data, the first number I represents the iSecret1 element, and the second data j represents the j + 1 content within the iTunes 1 element.
/ / 1, I = 0 I