C# 中的可空方法参数 [英] Nullable Method Arguments in C#

查看:24
本文介绍了C# 中的可空方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复问题

将空参数传递给 C# 方法

我可以在 c# 中为 .Net 2.0 执行此操作吗?

Can I do this in c# for .Net 2.0?

public void myMethod(string astring, int? anint)
{
//some code in which I may have an int to work with
//or I may not...
}

如果没有,我可以做类似的事情吗?

If not, is there something similar I can do?

推荐答案

是的,假设您有意添加了 V 字形并且您的意思是:

Yes, assuming you added the chevrons deliberately and you really meant:

public void myMethod(string astring, int? anint)

anint 现在将具有 HasValue 属性.

anint will now have a HasValue property.

这篇关于C# 中的可空方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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