in T1
-
此委托封装的方法的第一个参数类型。
该类型参数是逆变的。即可以使用指定的类型或派生程度更低的类型。有关协变和逆变的更多信息,请参见泛型中的协变和逆变。
- in T2
-
此委托封装的方法的第二个参数类型。
- in T3
-
此委托封装的方法的第三个参数类型。
- out TResult
-
此委托封装的方法的返回值类型。
该类型参数是协变的。即可以使用指定的类型或派生程度更高的类型。有关协变和逆变的更多信息,请参见泛型中的协变和逆变。
参数
- arg1
- 类型:T1
此委托封装的方法的第一个参数。
- arg2
- 类型:T2
此委托封装的方法的第二个参数。
- arg3
- 类型:T3
此委托封装的方法的第三个参数。
返回值
类型:TResult此委托封装的方法的返回值。
备注
也就是说,封装的方法必须具有三个均通过值传递给它的参数,并且必须返回值
随后在查询中使用封装此方法的委托来筛选字符串数组中的字符串。
using System;
using System.Collections.Generic;
using System.Linq;
public class Func3Example
{
public static void Main()
{
Func<String, int, bool> predicate = (str, index) => str.Length == index;
String[] words = { "orange", "apple", "Article", "elephant", "star", "and" };
IEnumerable<String> aWords = words.Where(predicate).Select(str => str);
foreach (String word in aWords)
Console.WriteLine(word);
}
}
。