zoukankan      html  css  js  c++  java
  • ethereum(以太坊)(基础)--容易忽略的坑(三)

    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: u0000u0000u0000u00123D"
        }
        function f2() returns(bytes){
            return bytes(s1);//bytes: 0x6c696e79
        }
    }
  • 相关阅读:
    103. 二叉树的锯齿形层次遍历
    102. 二叉树的层次遍历
    94. 二叉树的中序遍历
    Redis和数据库 数据同步问题
    203. 移除链表元素
    19. 删除链表的倒数第N个节点
    237. 删除链表中的节点
    141. 环形链表
    2. 两数相加
    143. 重排链表
  • 原文地址:https://www.cnblogs.com/eilinge/p/10081501.html
Copyright © 2011-2022 走看看