13,005
回編集
細 (文字列「source lang」を「syntaxhighlight lang」に置換) |
細 (文字列「</source>」を「</syntaxhighlight>」に置換) |
||
34行目: | 34行目: | ||
// ラムダ式を更に短く記述 | // ラムダ式を更に短く記述 | ||
Func<string, bool> predicate = str => str.Length < 5; | Func<string, bool> predicate = str => str.Length < 5; | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
<syntaxhighlight lang="csharp"> | <syntaxhighlight lang="csharp"> | ||
48行目: | 48行目: | ||
int count = CountList(names, str => str.Length < 5); | int count = CountList(names, str => str.Length < 5); | ||
} | } | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
以下の例では、LINQのCountメソッドを記述している。<br> | 以下の例では、LINQのCountメソッドを記述している。<br> | ||
55行目: | 55行目: | ||
<syntaxhighlight lang="csharp"> | <syntaxhighlight lang="csharp"> | ||
int count = names.Count(str => str.Length < 5); | int count = names.Count(str => str.Length < 5); | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
また、拡張メソッドと型推論を知ることで、LINQをより理解することができる。<br> | また、拡張メソッドと型推論を知ることで、LINQをより理解することができる。<br> | ||
70行目: | 70行目: | ||
ParameterExpression en = (ParameterExpression)lt.Left; | ParameterExpression en = (ParameterExpression)lt.Left; | ||
ConstantExpression zero = (ConstantExpression)lt.Right; | ConstantExpression zero = (ConstantExpression)lt.Right; | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
インタプリタ型の関数型言語には、匿名関数と式木データを区別しないものがあり、ある時はラムダ式を匿名関数として、またある時は式木データとして使用することができる。<br> | インタプリタ型の関数型言語には、匿名関数と式木データを区別しないものがあり、ある時はラムダ式を匿名関数として、またある時は式木データとして使用することができる。<br> | ||
93行目: | 93行目: | ||
return sum * prod; | return sum * prod; | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
<br> | <br> | ||
また、LINQ to SQLでは、ラムダ式の式木データを使用して、LINQクエリ式の条件式等を式木データとして取得し、<br> | また、LINQ to SQLでは、ラムダ式の式木データを使用して、LINQクエリ式の条件式等を式木データとして取得し、<br> | ||
118行目: | 118行目: | ||
FROM [Customers] AS [t0] | FROM [Customers] AS [t0] | ||
WHERE [t0].[City] = @p0 | WHERE [t0].[City] = @p0 | ||
</ | </syntaxhighlight> | ||
<br><br> | <br><br> | ||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ:C_Sharp]] | [[カテゴリ:C_Sharp]] |