Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the most elegant lambda expression (action) that does nothing?

So I currently have the following code:

    BCLThread bclThread = new BCLThread(() => Thread.Sleep(0));

because I can't think of another way to state that I actually don't want that method to do a thing. Is there any other more elegant way of achieving this?

Thanks

like image 541
devoured elysium Avatar asked Jan 03 '11 08:01

devoured elysium


People also ask

What does => mean in Lambda?

In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.

What is the point of lambdas?

Lambda functions are intended as a shorthand for defining functions that can come in handy to write concise code without wasting multiple lines defining a function. They are also known as anonymous functions, since they do not have a name unless assigned one.

What is lambda expression in C# used for?

Lambda expressions in C# are used like anonymous functions, with the difference that in Lambda expressions you don't need to specify the type of the value that you input thus making it more flexible to use. The '=>' is the lambda operator which is used in all lambda expressions.


2 Answers

Why not

BCLThread bclThread = new BCLThread(() => {});

?

like image 82
Victor Haydin Avatar answered Sep 22 '22 14:09

Victor Haydin


Action a = delegate { };
Action b = () => { };
like image 26
fejesjoco Avatar answered Sep 22 '22 14:09

fejesjoco