主要是取得2個Collection 裏,相同、相異、聯集的部份<转>

必需加入的dll: Iesi.Collections.dl
範例:
代码
using System;
using Iesi.Collections.Generic;

public partial class TestPage_SetDemoPage : System.Web.UI.Page {
    
protected void Page_Load(object sender, EventArgs e) {
        ISet
<string> Girls = new HashedSet<string>();
        Girls.Add(
"Christine");
        Girls.Add(
"Eva");
        Girls.Add(
"Jean");
        Girls.Add(
"Novia");
        Girls.Add(
"Winnie");

        ISet
<string> PMs = new HashedSet<string>();
        PMs.Add(
"Eva");
        PMs.Add(
"Novia");
        PMs.Add(
"Vincent");
        PMs.Add(
"Williams");
        PMs.Add(
"Winnie");

        ISet
<string> GirlPMs = Girls.Intersect(PMs);        
        Response.Write(
"是女生且是PM: <br />");
        
foreach (string s in GirlPMs) {
            Response.Write(s 
+ "<br />");
        }

        Response.Write(
"<br />");
        ISet
<string> GirlNotPMs = Girls.Minus(PMs);
        Response.Write(
"是女生且不是PM: <br />");
        
foreach (string s in GirlNotPMs) {
            Response.Write(s 
+ "<br />");
        }

        Response.Write(
"<br />");
        ISet
<string> GirlOrPMs = Girls.Union(PMs);
        Response.Write(
"是女生或是PM: <br />");
        
foreach (string s in GirlOrPMs) {
            Response.Write(s 
+ "<br />");
        }

        Response.Write(
"<br />");
        ISet
<string> NotMatch = Girls.ExclusiveOr(PMs);
        Response.Write(
"是女生但不是PM,或是PM但不是女生: <br />");
        
foreach (string s in NotMatch) {
            Response.Write(s 
+ "<br />");
        }
    }
}

 dll下载

原文地址:http://blog.blueshop.com.tw/uni2tw/archive/2008/02/14/54315.aspx

原文地址:https://www.cnblogs.com/wenjl520/p/1957975.html