什么都不做关键字在C#中? [英] Do nothing keyword in C#?

查看:139
本文介绍了什么都不做关键字在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在C#



例如关键字'做什么'我想用一个三元算哪里的行动之一就是不采取行动?

  officeDict.ContainsKey(0)?什么都不做:officeDict.Add(0,)


解决方案

没有,有没有这样的关键字。此外,运营商并不意味着来决定的动作的。它的意思来决定的的(或者,更从技术上说,值表达式的)。



您真的,真的想使用if条件这种决策,而不是:

 如果(!officeDict.ContainsKey(0))
officeDict.Add(0,);


Is there a keyword to 'do nothing' in C#?

For example I want to use a ternary operator where one of the actions is to take no action:

officeDict.ContainsKey("0") ? DO NOTHING : officeDict.Add("0","")

解决方案

No, there is no such keyword. Besides, the ?: operator is not meant for deciding actions. It's meant for deciding values (or, more technically, value expressions).

You really, really want to use an if condition for this sort of decision-making instead:

if (!officeDict.ContainsKey("0"))
    officeDict.Add("0", "");

这篇关于什么都不做关键字在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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