数组做方法入口参数
在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);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
当然如果方法不是内联的,入参的类型也必须定义成anytype,字符串也必须是定长的.
从使用者的角度我想不出为什么要这样设计......
1.字符串数组中字符串必须是定长的.
2.如果方法不是内联的,必须定义为anytype.
举例如下:
1.int类型数组,内联方法
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
2.int类型数组,非内联方法
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
上面的代码是不能通过编译的,必须把被调用方法的入参类型改成anytype数组才行.
3.string类型数组,内联函数
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
上述代码不能通过编译,错误内容为:对该类型的数组进行了非法操作.
把strTest改成定长字符串类型就可以通过了.
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
当然如果方法不是内联的,入参的类型也必须定义成anytype,字符串也必须是定长的.
从使用者的角度我想不出为什么要这样设计......