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,字符串也必须是定长的.
    从使用者的角度我想不出为什么要这样设计......
  • 相关阅读:
    在c#中使用全局快捷键
    把其他C/C++编译器集成到VC2005中
    零基础学习Oracle 10G视频教程
    异常处理 Exception
    序列化与反序列化 BinaryFormatter二进制(.dat)、SoapFormatter(.soap)、XmlSerializer(.xml)
    MVC 数据验证
    MVC 路由规则
    分部类,分部方法 修饰符partial
    HttpRuntime类
    MVC 模型绑定
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/530289.html
Copyright © 2011-2022 走看看