Easier way to use void function in Linq
See original GitHub issueBelow example, I use fun() to wrap WriteLine function. But it’s a little bit redundant … Is any easier way to use void function in Linq ?
public Subsystem<string> Upgrade(string path) =>
from fileinfo in TryGetFileInfo(path)
let _ = fun(() => Console.WriteLine($"File {fileinfo.Fullname} size is {fileinfo.length} byte."))()
from content in ReadFile(fileinfo)
select content;
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Sending items in a LINQ sequence to a method that returns ...
First of all, your current code will not work. Select , and most other LINQ methods, use deferred execution, meaning that they don't ......
Read more >Linq IEnumerable extensions for void functions
I found myself wanting to use Linq to map void methods to an IEnumerable to modify all items. The existing Linq methods require...
Read more >How do I return data from a void statement in C# using Linq
You cannot use return in a void method to return any value - becasue declaring a method as void is explicitly saying "this...
Read more >Write LINQ queries in C# | Microsoft Learn
This example shows how to use method syntax on the results of a query clause. Just enclose the query expression in parentheses, and...
Read more >7 tricks to simplify your programs with LINQ - Igor Ostrovsky
If so, you are quite wrong! Igor Ostrovsky has put together an excellent post outlining simple, yet effective, ways to use LINQ to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
At a computer now, so this will work:
Unfortunately, you do need to provide the generic parameter.
We can slightly improve the syntax from
to
with this additional
ignore
method