zoukankan      html  css  js  c++  java
  • 数组做方法入口参数

    在X++中数组类型做入口参数如下两点需要注意:
    1.字符串数组中字符串必须是定长的.
    2.如果方法不是内联的,必须定义为anytype.
    举例如下:
    1.int类型数组,内联方法
    static void InputParameterTest(Args args)
    {
        
    int intTest[2];
        
    //inline method
        void intArrayInputParameterTest(int inputParameter[])
        
    {
            print inputParameter[
    1];
            print inputParameter[
    2];
            pause;
        }

        intTest[
    1= 100;
        intTest[
    2= 200;
        intArrayInputParameterTest(intTest);
       }
    上述代码可以正确编译运行.
    2.int类型数组,非内联方法
    //调用方法
    static void Main(Args args)
    {
        
    int intTest[2];
        ;
        intTest[
    1= 100;
        intTest[
    2= 200;
        intArrayInputParameterTest(intTest);
      InputParameterTest::intArrayInputParameterTest(intTest);
    }

    //被调用方法
    static void intArrayInputParameterTest(int inputParameter[])
    {
            print inputParameter[
    1];
            print inputParameter[
    2];
            pause;
    }

    上面的代码是不能通过编译的,必须把被调用方法的入参类型改成anytype数组才行.
    3.string类型数组,内联函数
    static void Main(Args args)
    {
         str strTest[
    2];
         
    void strArrayInputParameterTest(str inputParameter[])
        
    {
            print inputParameter[
    1];
            print inputParameter[
    2];
            pause;
        }

        ;
       
        strTest[
    1= "First";
        strTest[
    2= "Second";
        
    //call inline method
        strArrayInputParameterTest(strTest);
     }

    上述代码不能通过编译,错误内容为:对该类型的数组进行了非法操作.
    把strTest改成定长字符串类型就可以通过了.
    static void Main(Args args)
    {
         str 
    100 strTest[2];
         
    void strArrayInputParameterTest(str 100 inputParameter[])
        
    {
            print inputParameter[
    1];
            print inputParameter[
    2];
            pause;
        }

        ;
        strTest[
    1= "First";
        strTest[
    2= "Second";
         
    //call inline method
        strArrayInputParameterTest(strTest);

       }

    当然如果方法不是内联的,入参的类型也必须定义成anytype,字符串也必须是定长的.
    从使用者的角度我想不出为什么要这样设计......
  • 相关阅读:
    微人事项目-mybatis-持久层
    通过外键连接多个表
    springioc
    Redis 消息中间件 ServiceStack.Redis 轻量级
    深度数据对接 链接服务器 数据传输
    sqlserver 抓取所有执行语句 SQL语句分析 死锁 抓取
    sqlserver 索引优化 CPU占用过高 执行分析 服务器检查
    sql server 远程备份 bak 删除
    冒泡排序
    多线程 异步 beginInvoke EndInvoke 使用
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/530289.html
Copyright © 2011-2022 走看看