Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create struct structure in solidity

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to create struct structure in solidity? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The use of solidity structures is similar to that of some languages.

Contract Code:

Pragma solidity ^ 0.4.20 position contract Test {People p; struct People {uint256 age;} / / define the function modifier modifier age18 (uint256 age) {require (age > = 18); _;} / / set method, modify the set function function set (uint256 x) public age18 (x) {p=People (x) with the function modifier age18 } / / returns the age content in the structure variable function get () public constant returns (uint256) {return p. Age;}}

Code parsing, which only describes the other contents of the previous section of the structure:

People pTX:

Declare the People structure variable p, which is no different from something like a C language structure.

Struct People {

Uint256 age

}

Defines a People structure, where the structure variable age is a uint type, which is not different from some language structure definitions.

P=People (x);

Initialize structure People and assign values to p structure variables

Return p. AgeX:

Returns the value of age in the structure variable p.

This is the answer to the question about how to create the struct structure in solidity. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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: 235

*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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report