ethereum(以太坊)(基础)--容易忽略的坑(三)

Posted on 2018-12-07 10:41  eilinge  阅读(600)  评论(0编辑  收藏  举报
pragma solidity ^0.4.10;

contract Byte{
    
    bytes [] public T=new bytes[](3);
    
    function setLeng(uint len) public{
        T.length=len;
        T.push('0x11');
    }
    
    //bytes [5] public T1=new bytes[](5);
    //Type bytes memory[] memory is not implicitly convertible to 
    //expected type bytes storage ref[5] storage ref
    
    //bytes [5] public T1 = [1,2,3,4,5];
    //Type uint8[5] memory is not implicitly convertible to expected 
    //type bytes storage ref[5] storage ref
    
    uint [5] public T1=[1,2,3,4,5];
    
    //bytes [2] public T2 = [0x11,0x12];
    //uint [] storage T2= new uint[](5);Expected identifier, got 'Storage'
    
    
    uint []  public T2= new uint[](5);
    function setLeng1(uint len) public{
        //T1.length=len;//Expression has to be an lvalue
        //uint [5] memory T0=[1,2,3,4,5];Type uint8[5] memory is not implicitly convertible to expected type uint256[5] memory
        uint [5] memory T1=[uint(1),2,3,4,5];
        for (uint i;i<T1.length;i++){
            T2[i] = T1[i];
        }
    }
    
    
    function getByte() view public returns(bytes){
        //return T;
        //return bytes(T2);
    }
    
    bytes3 public b=0x123344;
    byte[3] public b1;
    bytes public b2 = new bytes(3);
    string public s1="liny";
    
    function f0() public{
        for(uint i;i<b.length;i++){
            b2.push(b[i]);
        }
    }
    function f1() returns(string){
        return string(b2);//"string: \u0000\u0000\u0000\u00123D"
    }
    function f2() returns(bytes){
        return bytes(s1);//bytes: 0x6c696e79
    }
}