Because the. NET Framework does not provide the set operation function, we can use a third-party class library to implement this function (now with the LINQ, it is much more convenient ). There is an iesi. collection. dll in the Nhibernate framework. This Class Library provides the set operation function and supports generics.
Function: obtains the same, different, and connected parts of two sets. Example:
Using system; using system. data; using system. configuration; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; using iesi. collections. generic; public partial class _ default: 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 ("Girl and PM: <br/>"); foreach (string s in girlpms) {response. write (S + "<br/>");} response. write ("<br/>"); Iset <string> girlnotpms = girls. minus (PMS); response. write ("is a girl and not pm: <br/>"); foreach (string s in girlnotpms) {response. write (S + "<br/>");} response. write ("<br/>"); Iset <string> girlorpms = girls. union (PMS); response. write ("is a girl or PM: <br/>"); foreach (string s in girlorpms) {response. write (S + "<br/>");} response. write ("<br/>"); Iset <string> notmatch = girls. exclusiveor (PMS); response. write ("girl, not pm, or PM, but not girl: <br/>"); foreach (string s in notmatch) {response. write (S + "<br/> ");}}}
Running result:
Is a girl and PM:
Eva
Novia
Winnie
It's a girl and not a PM:
Christine
Jean
Is a girl or PM:
Christine
Eva
Jean
Novia
Winnie
Vincent
Williams
It's a girl but not a PM, or a PM but not a girl:
Christine
Williams
Jean
Vincent
Supplement: 1. If order is important, hashedset can be changed to sortedset2. if sortedset is used, the elements in the set must inherit the icomparable interface.
3. For more details, refer
Add support for "set" collections to. net