I have come across this code in MoreLinq, in file Batch.cs
(link):
return _(); IEnumerable<TResult> _()
I read up on discards, but nevertheless I cannot make sense of the above code. When I hover above the first _
it says: "Variables captured: resultSelector, collection".
_()
represent?return _();
, how can the subsequent code IEnumerable<TResult> _()
still be executed?The duplicate-checking formula uses =COUNTIF to “count” which cells contain data that appears more than once throughout the spreadsheet. Resulting values can either be “TRUE” (indicating duplicate data) or “FALSE” (showing non-duplicate data).
We can remove duplicate element in an array by 2 ways: using temporary array or using separate index. To remove the duplicate element from array, the array must be in sorted order. If array is not sorted, you can sort it by calling Arrays. sort(arr) method.
Quick formatting Select one or more cells in a range, table, or PivotTable report. On the Home tab, in the Style group, click the small arrow for Conditional Formatting, and then click Highlight Cells Rules, and select Duplicate Values. Enter the values that you want to use, and then choose a format.
The _()
here is a call to the local function called _
. Unusual, but valid.
A local function is broadly like a regular method, except that it can only be called by name (i.e. the usual way you call a method) from inside the method that declares it (as Eric points out in a comment, there are some other ways that it could be called, for example via a delegate passed out from the method), and (unless decorated static
) it can pick up locals and parameters from the declaring method as state.
In this case, the intent is to perform eager parameter validation.
With validation code in the iterator block, the parameters validation would be deferred until the first MoveNext()
call. (i.e. it wouldn't complain about source
being null
until someone attempts to foreach
over the data).
IEnumerable<TResult> _() {}
is local function that called in return _();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With