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
            */


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章