Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the being called here: return _() [duplicate]

Tags:

c#

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".

  • What do the two _() represent?
  • Since we are doing a return _();, how can the subsequent code IEnumerable<TResult> _() still be executed?
like image 975
Robotronx Avatar asked Jan 27 '20 07:01

Robotronx


People also ask

What is the duplicate formula in Excel?

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).

How do I get rid of duplicate elements?

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.

How do you duplicate values in Excel?

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.


2 Answers

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).

like image 134
Marc Gravell Avatar answered Oct 28 '22 22:10

Marc Gravell


IEnumerable<TResult> _() {} is local function that called in return _();

like image 27
Kovpaev Alexey Avatar answered Oct 28 '22 21:10

Kovpaev Alexey