Linq的限定符操作

限定符运算返回一个 Boolean 值,该值指示序列中是否有一些元素满足条件或是否所有元素都满足条件。

方法名

说明

C# 查询表达式语法

Visual Basic 查询表达式语法

更多信息

全部

确定是否序列中的所有元素都满足条件。

不适用。

Aggregate … In … Into All(…)

Enumerable.All<TSource>

Queryable.All<TSource>

Any

确定序列中是否有元素满足条件。

不适用。

Aggregate … In … Into Any()

Enumerable.Any

Queryable.Any

Contains

确定序列是否包含指定的元素。

不适用。

不适用。

Enumerable.Contains

Queryable.Contains


ALL的用法

       class Pet
            {
                public string Name { get; set; }
                public int Age { get; set; }
            }

            public static void AllEx()
            {
                // Create an array of Pets.
                Pet[] pets = { new Pet { Name="Barley", Age=10 },
                               new Pet { Name="Boots", Age=4 },
                               new Pet { Name="Whiskers", Age=6 } };

                // Determine whether all pet names 
                // in the array start with 'B'.
                bool allStartWithB = pets.All(pet =>
                                                  pet.Name.StartsWith("B"));

                Console.WriteLine(
                    "{0} pet names start with 'B'.",
                    allStartWithB ? "All" : "Not all");
            }

            // This code produces the following output:
            //
            //  Not all pet names start with 'B'. 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值