Enumerable.All<(Of <(TSource>)>) 方法
Enumerable.All<(Of <(TSource>)>) 方法
确定序列中的所有元素是否满足条件。
语法
public static bool<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate
)
类型参数
TSource
source 中的元素的类型。
参数
source
类型:System.Collections.Generic.IEnumerable<(Of <(TSource>)>)
包含要应用谓词的元素的 IEnumerable<(Of <(T>)>)。
predicate
类型:System.Func<(Of <(TSource, Boolean>)>)
用于测试每个元素是否满足条件的函数。
返回值
类型:System.Boolean
如果源序列中的每个元素都通过指定谓词中的测试,或者序列为空,则为 true;否则为 false。
使用说明
在 Visual Basic 和 C# 中,可以在 IEnumerable<(Of <(TSource>)>) 类型的任何对象上将此方法作为实例方法来调用。当使用实例方法语法调用此方法时,请省略第一个参数。
public class LinqAll
{
public static void Show(object obj)
{
HttpContext.Current.Response.Write("<BR>" + obj.ToString());
}
public static void AllDemo()
{
int[] nums = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
bool tag = nums.All((i) => { return i > 8; });
Show(tag);
var strs = new[] { "a", "b", "c", "d" };
tag = strs.All<string>((s) => { LinqAggregate.Show(s); return s.ToCharArray()[0] > 75; });
Show(tag);
}
}
调用:
protected void Page_Load(object sender, EventArgs e)
{
LinqAll.AllDemo();
}
结果:
False
a
b
c
d
True
{
public static void Show(object obj)
{
HttpContext.Current.Response.Write("<BR>" + obj.ToString());
}
public static void AllDemo()
{
int[] nums = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
bool tag = nums.All((i) => { return i > 8; });
Show(tag);
var strs = new[] { "a", "b", "c", "d" };
tag = strs.All<string>((s) => { LinqAggregate.Show(s); return s.ToCharArray()[0] > 75; });
Show(tag);
}
}
调用:
protected void Page_Load(object sender, EventArgs e)
{
LinqAll.AllDemo();
}
结果:
False
a
b
c
d
True
浙公网安备 33010602011771号