ラムダ ディスカード パラメーターLambda discard parameters
まとめSummary
破棄 ( _
) をラムダおよび匿名メソッドのパラメーターとして使用できるようにします。Allow discards (_
) to be used as parameters of lambdas and anonymous methods.
次に例を示します。For example:
- ラムダ:
(_, _) => 0
、(int _, int _) => 0
lambdas:(_, _) => 0
,(int _, int _) => 0
- 匿名メソッド:
delegate(int _, int _) { return 0; }
anonymous methods:delegate(int _, int _) { return 0; }
目的Motivation
未使用のパラメーターに名前を付ける必要はありません。Unused parameters do not need to be named. 破棄の目的は明確ではありません。つまり、未使用または破棄されます。The intent of discards is clear, i.e. they are unused/discarded.
詳細なデザインDetailed design
メソッドパラメーター ラムダまたは匿名メソッドのパラメーターリストに複数のパラメーターが指定されて _
いる場合、このようなパラメーターは破棄パラメーターです。Method parameters In the parameter list of a lambda or anonymous method with more than one parameter named _
, such parameters are discard parameters.
注: 1 つのパラメーターに名前が付けられている場合は、旧バージョンと _
の互換性のために通常のパラメーターになります。Note: if a single parameter is named _
then it is a regular parameter for backwards compatibility reasons.
破棄パラメーターでは、どのスコープにも名前は導入されません。Discard parameters do not introduce any names to any scopes.
これは、 _
(アンダースコア) 名が非表示にならないことを意味します。Note this implies they do not cause any _
(underscore) names to be hidden.
簡易名K
が0で 、ブロック 内に simple_name が含まれていて、ブロック の (またはそれを囲む ブロック の) ローカル変数宣言領域 (宣言) にローカル変数、パラメーター (破棄パラメーターを除く)、または名前を持つ定数が含まれている場合、 I
simple_name はそのローカル変数、パラメーター、または定数を参照し、変数または値としてSimple names If K
is zero and the simple_name appears within a block and if the block's (or an enclosing block's) local variable declaration space (Declarations) contains a local variable, parameter (with the exception of discard parameters) or constant with name I
, then the simple_name refers to that local variable, parameter or constant and is classified as a variable or value.
スコープDiscard パラメーターを除き、 lambda_expression (匿名関数式) で宣言されたパラメーターのスコープは、discard パラメーターを除き、 lambda_expression の anonymous_function_body であり、 anonymous_method_expression (匿名関数式) で宣言されたパラメーターのスコープはその anonymous_method_expression の ブロック です。Scopes With the exception of discard parameters, the scope of a parameter declared in a lambda_expression (Anonymous function expressions) is the anonymous_function_body of that lambda_expression With the exception of discard parameters, the scope of a parameter declared in an anonymous_method_expression (Anonymous function expressions) is the block of that anonymous_method_expression.