• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    LINQ基本操作

    發布: 2008-5-07 13:51 | 作者: 網絡轉載 | 來源: 本站原創 | 查看: 24次 | 進入軟件測試論壇討論

    領測軟件測試網 首先我們創建2個類,一個Category,一個Product
    public class Product { public string Name { get; set; } public int CategoryID { get; set; } } public class Category { public string Name { get; set; } public int ID { get; set; } }
      然后創建2個List的數據源
    static List<Category> categories = new List<Category>() { new Category(){Name="Beverages", ID=001}, new Category(){Name="Condiments", ID=002}, new Category(){Name="Vegetables", ID=003}, new Category(){Name="Grains", ID=004}, new Category(){Name="Fruit", ID=005}, new Category(){Name="Other", ID=006} }; static List<Product> products = new List<Product>() { new Product{Name="Cola", CategoryID=001}, new Product{Name="Tea", CategoryID=001}, new Product{Name="Mustard", CategoryID=002}, new Product{Name="Pickles", CategoryID=002}, new Product{Name="Carrots", CategoryID=003}, new Product{Name="Bok Choy", CategoryID=003}, new Product{Name="Peaches", CategoryID=005}, new Product{Name="Melons", CategoryID=007}, };
      好了,現在我們開始使用LINQ了,下面使用的表達式和方法的結果是一樣的,這里的方法指Lambda表達式


      l 使用排序

      1. 使用排序時使用的顯示語句
    foreach (var c in orderByResult) Console.WriteLine("ID={0},Name={1}", c.ID, c.Name);
      2. 升序 

      表達式
    var orderByResult = from c in categories orderby c.ID //默認為升序,也可以在后面加上ascending select c; // 方法 var orderByResult = categories.OrderBy(c=>c.ID);
      3. 降序

      表達式
    var orderByResult = from c in categories orderby c.ID descending select c; // 方法 var orderByResult = categories.OrderByDescending(c=>c.ID);

      4. 多個屬性的升序

      表達式

    var orderByResult = from c in categories orderby c.ID,c.Name select c; //方法 var orderByResult = categories.OrderBy(c=>c.ID).ThenBy(c=>c.Name);
      5. 多個屬性的降序排列

      表達式
    var orderByResult = from c in categories orderby c.ID, c.Name descending select c; //方法 var orderByResult = categories.OrderByDescending(c=>c.ID).ThenByDescending(c=>c.Name);

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    TAG: LINQ Linq


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>