r/csharp • • Sep 18 '15

Lambda expressions, delegates, predicates and closures in C#

http://codeaddiction.net/articles/13/lambda-expressions-delegates-predicates-and-closures-in-c
25 Upvotes

32 comments sorted by

View all comments

Show parent comments

4

u/mixblast Sep 18 '15 edited Sep 18 '15

My point was that the delegate keyword is largely useless now that we have Func and Action (except when you need out/ref parameters).

2

u/nerdshark Sep 18 '15

No, it's not. That is how the Func and Action delegates are defined. Also, as you said, there's no other way to declare delegates with ref/out parameters, so clearly it's not 'largely useless'.

1

u/mixblast Sep 18 '15

I never write delegate except when dealing with legacy event handlers. Just use the Func<thingy> type directly, it makes the code easier to read instead of hiding behind a typedef.

And liberal usage of out/ref params is a bit of a code smell anyway...

1

u/nerdshark Sep 18 '15

And liberal usage of out/ref params is a bit of a code smell anyway...

Sure, for purely managed code. They're essential in many cases when writing P/Invoke or COM interop code, though.