欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

LINQ基礎(chǔ)之Intersect、Except和Distinct子句

 更新時(shí)間:2022年04月20日 10:57:18   作者:農(nóng)碼一生  
這篇文章介紹了LINQ使用Intersect、Except和Distinct子句的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

Intersect子句

一、簡介

Intersect返回交集,交集是指同時(shí)出現(xiàn)在兩個(gè)集合中的元素,和數(shù)據(jù)庫中的Intersect方法實(shí)現(xiàn)功能一樣。

二、案例

var q =  (from c in db.Customers            
          select c.Age         
         ).Intersect(             
                    from e in db.Employees             
                    select e.Age
         );

Except子句

一、簡介

Except返回差集,差集是指位于一個(gè)集合但不位于另一個(gè)集合的元素。Except是把第一個(gè)集合里面的數(shù)據(jù) 去掉在第二個(gè)集合里面出現(xiàn)過的數(shù)據(jù)。

二、案例

案例一:

var q = (from c in db.Customers    
        select c.Name
        ).Except(from e in db.Employees     
                 select e.Name
 );

案例二:

//1 2 這兩條記錄

var q1 = from s in db.Student
      where s.ID < 3
      select s;

 //1 2 3 4 這四條記錄
var q2 = from s in db.Student
      where s.ID < 5
      select s;

var r = q1.Except(q2).ToList();// 空
var r2 = q2.Except(q1).ToList();//3 4

Distinct子句

一、簡介

Distinct返回的序列包含輸入序列的唯一元素,該語句是單個(gè)集合操作。

二、案例

List<int> list = new List<int>() {1,2,3,3,3};
var result = list.Distinct();

Result的結(jié)果為:{1,2,3}

到此這篇關(guān)于LINQ使用Intersect、Except和Distinct子句的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論