7
以下のC#コードでは、私は_()
の使用が奇妙であることがわかりました。誰でもこれが何を意味するのか説明できますか?シンタックスの意味:return _(); IEnumerable <TSource> _()
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
return _(); IEnumerable<TSource> _()
{
var knownKeys = new HashSet<TKey>(comparer);
foreach (var element in source)
{
if (knownKeys.Add(keySelector(element)))
yield return element;
}
}
}
私は本当にこのパターンがつかまないことを願っています。それはちょうど醜いです。 –
ローカル関数がどのような種類の識別キーワードをも欠いていることは決してありませんでした。例えば、ローカルデリゲートやオブジェクトイニシャライザリストでは混乱しやすいでしょう。単純な 'func'キーワードまたは必須のラムダ構文' => 'が役立ちます。 – Dai
ローカルの機能はここでは必要ありません。 –