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,字符串也必须是定长的.
    从使用者的角度我想不出为什么要这样设计......
  • 相关阅读:
    python3 pyinstaller
    python3 random
    python3 turtle
    产生一个序列的所有排列组合
    蒙特卡洛算法
    lightoj 1014
    UVA11426
    nginx 配置本地https(免费证书)
    ElementUI
    Airbnb 代码规范
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/530289.html
Copyright © 2011-2022 走看看