solidity智能合约[10]-动态字节数组

动态字节数组的定义

bytes 变量名 = new bytes(大小);

动态字节数组的属性

可以修改大小和长度

动态字节数组默认初始化为0

bytes public name = new bytes(2);
name的值一开始为0x0000

动态字节数组的赋值

1
2
3
4
function InitName()  public{
     name[0] = 0x6a;
     name[1] =0x6f;
 }

动态字节数组的属性

1
2
3
function getLength() view public  returns(uint){
    return name.length;
}

动态字节数组修改长度和添加变量

1
2
3
4
5
6
7
8
9
function changeLength() public{
   name.length = 5;
}
//添加到后方
function pushBytes() public{

   name.push(0x99);

}

image.png

猜你喜欢

转载自blog.51cto.com/13784902/2320204