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
        }
    }
  • 相关阅读:
    [草稿]挂载新硬盘
    [Android]开发环境配置(windows)-draft
    [草稿][C语言][内存分配]常见内存错误
    [草稿]Linux用户管理
    python的异步编程、IO多路复用、协程
    python的网络编程(socket)
    python的多进程、logging模
    python的Lock锁,线程同步
    python的并发和线程
    python的异常处理
  • 原文地址:https://www.cnblogs.com/eilinge/p/10081501.html
Copyright © 2011-2022 走看看