c# - 从 C++ : how to pass nullptr to DateTime? 调用 C#

标签 c# c++-cli nullable

在 C# 程序集中,我得到了一个以可为空的 DateTime 作为参数的函数:

public void DoSomething(DateTime? timestamp);

现在我想从 c++/cli 调用这个方法:

MyClass->DoSomething(nullptr);

这不会编译。相反,c++ 编译器将打印一条错误消息 nullptr cannot be converted to System::Nullable。

那么如何将 nullptr 从 C++ 传递到可为 null 的 DateTime?

最佳答案

MyClass->DoSomething(Nullable<DateTime>());

How to use Nullable types in c++/cli?

关于c# - 从 C++ : how to pass nullptr to DateTime? 调用 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5501815/

相关文章:

templates - CLI/C++接口(interface)类,通用方法调用模板方法

c# - 在使用 int 对象 ID 时,我应该使用可为 null 的 int 吗?

c# - 如何获取字节数组的TypeCode?

C# Windows 窗体用户控件控件设计器支持

c# - 无法将类型 'Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<T>' 隐式转换为 'T'

c# - 添加 asp :button to panel using C# 时出现问题

.net - 了解 gcroot

c++ - 托管 C++ 中的运算符重载

fluent-nhibernate - 非空字段的 Fluent Nhibernate Automap 约定

flutter - Dart比较int null安全问题: operator can't be unconditionally invoked because the receiver can be 'null'