Linq筛选数据

<table style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; border-collapse: collapse; padding: 0px; width: 913px; border: 1px solid rgb(187, 187, 187); color: rgb(0, 0, 0); font-size: 13px; line-height: 17px;"><tbody><tr><th style="border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; background-color: rgb(237, 237, 237); color: rgb(99, 99, 99); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important;"><p style="color: rgb(42, 42, 42); margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt6" class="sentence" data-guid="49a55a6615b7be817490ba58b1f4f8fd" data-source="Method Name" xml:space="preserve">方法名</span></p></th><th style="border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; background-color: rgb(237, 237, 237); color: rgb(99, 99, 99); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important;"><p style="color: rgb(42, 42, 42); margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt7" class="sentence" data-guid="67daf92c833c41c95db874e18fcb2786" data-source="Description" xml:space="preserve">说明</span></p></th><th style="border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; background-color: rgb(237, 237, 237); color: rgb(99, 99, 99); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important;"><p style="color: rgb(42, 42, 42); margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt8" class="sentence" data-guid="dbe711d9cb63cb5066ace3e0f3596c1c" data-source="C# Query Expression Syntax" xml:space="preserve">C# 查询表达式语法</span></p></th><th style="border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; background-color: rgb(237, 237, 237); color: rgb(99, 99, 99); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important;"><p style="color: rgb(42, 42, 42); margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt9" class="sentence" data-guid="21200205d09ea6b1485fa12329fd46c7" data-source="Visual Basic Query Expression Syntax" xml:space="preserve">Visual Basic 查询表达式语法</span></p></th><th style="border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; background-color: rgb(237, 237, 237); color: rgb(99, 99, 99); font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important;"><p style="color: rgb(42, 42, 42); margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt10" class="sentence" data-guid="5dc731e46ae38b87ff3e3e2eaf459db2" data-source="More Information" xml:space="preserve">更多信息</span></p></th></tr><tr><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt11" class="sentence" data-guid="9c9d5e9a50a7cfb57e236513da79d94e" data-source="OfType" xml:space="preserve">OfType</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt12" class="sentence" data-guid="2829fc9fb83254a8e6f9b6b7e3239db1" data-source="Selects values, depending on their ability to be cast to a specified type." xml:space="preserve">根据值强制转换为指定类型的能力选择值。</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt13" class="sentence" data-guid="a2d8e98f65bdf9f5c22398df2acade0e" data-source="Not applicable." xml:space="preserve">不适用。</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt14" class="sentence" data-guid="a2d8e98f65bdf9f5c22398df2acade0e" data-source="Not applicable." xml:space="preserve">不适用。</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><a target=_blank href="http://msdn.microsoft.com/zh-cn/library/bb360913(v=vs.100).aspx" style="text-decoration: none; color: rgb(3, 105, 122);">Enumerable<span xmlns="">.</span>OfType<span xmlns=""><</span>TResult<span xmlns="">></span></a></p><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><a target=_blank href="http://msdn.microsoft.com/zh-cn/library/bb344857(v=vs.100).aspx" style="text-decoration: none; color: rgb(3, 105, 122);">Queryable<span xmlns="">.</span>OfType<span xmlns=""><</span>TResult<span xmlns="">></span></a></p></td></tr><tr><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt15" class="sentence" data-guid="567904efe9e64d9faf3e41ef402cb568" data-source="Where" xml:space="preserve">Where</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span id="mt16" class="sentence" data-guid="c73b04914336890472aa05079d4a3780" data-source="Selects values that are based on a predicate function." xml:space="preserve">选择基于谓词函数的值。</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span class="code" style="font-family: Consolas, Courier, monospace; color: rgb(0, 100, 0);">where</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><span class="code" style="font-family: Consolas, Courier, monospace; color: rgb(0, 100, 0);">Where</span></p></td><td style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif !important; border: 1px solid rgb(187, 187, 187); margin: 10px; padding: 10px 8px; color: rgb(42, 42, 42); vertical-align: top;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px;"><a target=_blank href="http://msdn.microsoft.com/zh-cn/library/system.linq.enumerable.where(v=vs.100).aspx" style="text-decoration: none; color: rgb(3, 105, 122);">Enumerable<span xmlns="">.</span>Where</a></p><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; line-height: 18px;"><a target=_blank href="http://msdn.microsoft.com/zh-cn/library/system.linq.queryable.where(v=vs.100).aspx" style="text-decoration: none; color: rgb(3, 105, 122);">Queryable<span xmlns="">.</span>Where</a></p></td></tr></tbody></table>

          System.Collections.ArrayList fruits = new System.Collections.ArrayList(4);
            fruits.Add("Mango");
            fruits.Add("Orange");
            fruits.Add("Apple");
            fruits.Add(3.0);
            fruits.Add("Banana");

            // Apply OfType() to the ArrayList.
            IEnumerable<string> query1 = fruits.OfType<string>();

            Console.WriteLine("Elements of type 'string' are:");
            foreach (string fruit in query1)
            {
                Console.WriteLine(fruit);
            }

            // The following query shows that the standard query operators such as 
            // Where() can be applied to the ArrayList type after calling OfType().
            IEnumerable<string> query2 =
                fruits.OfType<string>().Where(fruit => fruit.ToLower().Contains("n"));

            Console.WriteLine("\nThe following strings contain 'n':");
            foreach (string fruit in query2)
            {
                Console.WriteLine(fruit);
            }

            // This code produces the following output:
            //
            // Elements of type 'string' are:
            // Mango
            // Orange
            // Apple
            // Banana
            //
            // The following strings contain 'n':
            // Mango
            // Orange
            // Banana


           string[] words = { "the", "quick", "brown", "fox", "jumps" };

            IEnumerable<string> query = from word in words
                                        where word.Length == 3
                                        select word;

            foreach (string str in query)
                Console.WriteLine(str);

            /* This code produces the following output:

                the
                fox
            */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值