固体:如何通过名称动态访问变量?
有没有一种方法可以使用另一个变量访问固体变量?
这样的事情:
contract Test {
uint age;
string varAge = "age";
function setAge() public {
// varAge should be able to access age variable
${varAge} = 30;
}
}
Is there a way to access variables in solidity using another variable?
Something like this:
contract Test {
uint age;
string varAge = "age";
function setAge() public {
// varAge should be able to access age variable
${varAge} = 30;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

不,这不像PHP。
我能想到的最接近的是拥有一个映射,例如
映射(String => uint)mymap;
。然后,您可以做mymap [“ abc”] = 123;
之类的事情,也可以做到这一点...
No. It's not like PHP.
The closest thing I can think of is having a mapping like
mapping(string=>uint) myMap;
. Then you can do stuff likemyMap["abc"] = 123;
You could also do this...