如何在c ++ / cli中使用Nullable类型? [英] How to use Nullable types in c++/cli?

查看:238
本文介绍了如何在c ++ / cli中使用Nullable类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我认为会工作:

I have the following code, which I thought would work:

property Nullable<double> Angle {
	Nullable<double> get() {
		return nullptr;
        }
}

我该怎么办呢?

推荐答案

OK,发现它,经过很多麻烦:

OK, found it, after a lot of hassle:

返回null,只是做

return Nullable<double>();

返回非null:

return Nullable<double>(12321);

重要的是声明返回值为 Nullable< double> code>而不是 Nullable< double> ^ ,如果你这样做,当使用其他语言作为C#和vb.net时,你会看到类型 ValueType 而不是 double?

It is important to declare the return value as Nullable<double> and not Nullable<double>^, as if you do it, when using other languages as C# and vb.net, you'll see the type as ValueType instead of double?.

这篇关于如何在c ++ / cli中使用Nullable类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆