首页 > 解决方案 > 可选参数可为空

问题描述

上下文:
在 Ax 中,我公开了一个 Web 服务。该方法采用 3 个参数。其中两个应该是Nullable<>,但我在 X++ 中没有这样做。

在 c# 中,代码如下所示:

private static void FooBar(string[] things, DateTime? d1, DateTime? d2)
{
    if (d1 == null || d2 == null)
    {
        //Do Something
    }
    else {
        //Something Else
    }
}

我怎么翻译这个?如何使用构建可选的可空参数构建方法?

X++不支持方法重载。

标签: x++

解决方案


这应该转化为以下内容:

private static void FooBar(str things[], utcdatetime d1 = DateTimeUtil::minValue(), utcdatetime d2 = DateTimeUtil::minValue())
{
    if(d1!=DateTimeUtil::minValue()||d2!=DateTimeUtil::minValue())
    {
        //do something
    }
    else
    {
        //something else
    }
}

things是强制性的,d1&d2是可选的


推荐阅读