简单的C#空操作语句 [英] Simple C# Noop Statement

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

问题描述

什么是C#中的简单NOOP声明,这并不需要实现的方法?
(内联/λ方法都行,但。)

What is a simple Noop statement in C#, that doesn't require implementing a method? (Inline/Lambda methods are OK, though.)

我目前的使用案例:我想占据的try-catch的追赶块,所以我可以进入它,而调试和检查异常。结果
我知道我可能应该处理/反正记录异常,但这不是这项工作的地步。

My current use case: I want to occupy the catch-block of a try-catch, so I can step into it while debugging and inspect the exception.
I'm aware I should probably be handling/logging the exception anyway, but that's not the point of this exercise.

推荐答案

如果你真的想空操作,那么这个定义了一个无名的行动,这并不做任何事情,然后调用它,导致没有发生:

If you really want noop, then this defines a nameless action that doesn't do anything, and then invokes it, causing nothing to happen:

((Action)(() => { }))();

这篇关于简单的C#空操作语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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