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

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

问题描述

有重复的问题

<一个href=\"http://stackoverflow.com/questions/271588/passing-null-arguments-to-c-methods/271600\">http://stackoverflow.com/questions/271588/passing-null-arguments-to-c-methods/271600

我可以用于.NET 2.0为此在C#中?

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 属性。

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

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