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[] { 12345678910 };
            
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 

 

 

posted on 2010-06-23 16:12  keely  阅读(542)  评论(0)    收藏  举报