Seemingly parentheses number not to CodePudding user response:
Merge to weight is actually and set Please use the Union method and set CodePudding user response:
Our problem is, of course, keep a???? Keep what?? According to the average person thinking with my new and old and retain new right I give an example of course written in c #, I don't ask me to vb.net, more than 10 years don't write vb.net grammar forget public class test { Public string id {get; set; } Public string name {get; set; } } The public class test comparator: IEqualityComparer { Public Boolean Equals (x test, the test y) { Return x.i d.E quals y.i (d); } Public int GetHashCode (test obj) { Return obj. Id. GetHashCode (); } } List LstA=new List (a); LstA. Add (new test () { Id="1" and name="1" }); LstA. Add (new test () { Id="2", Name="2", " }); List LstB=new List (a); LstB. Add (new test () { Id="1", Name="2", " }); LstB. Add (new test () { Id="3", Name="3" }); Var res=lstB. Union (lstA, new test comparator ()). The ToList (); CodePudding user response:
Need to use vb version of converting a https://converter.telerik.com/ Using System. Collections. Generic; Using System. Diagnostics; Using System. Linq; The namespace ConsoleApp1 { Class Program { The static void Main ( String [] args ) { List BsonList=new List () { New BsonDocument () { Id="1", Code=No. 1 ", " Codename="* *" }, New BsonDocument () { Id="2", Code=No. 2 ", " Codename="bill" }, New BsonDocument () { Id="3", Code="No. 3," Codename="detective" }, }; List List=new List () { New BsonDocument () { Id="1", Code=No. 1 ", " Codename="* *" }, New BsonDocument () { Id="2", Code=No. 2 ", " Codename="Li Er egg" }, New BsonDocument () { Id="3", Code="No. 3," Codename="king second" }, New BsonDocument () { Id="4", Code="No. 4," Codename="Wu Tiezhu" }, }; Var result=bsonList Concat (list) Distinct (new BsonDocumentComparer ()); The foreach (var bsonDocument result in) { The Debug. Print ($id: "{bsonDocument. Id} \ tcode: {bsonDocument. Code} \ tCodename: {bsonDocument. Codename} \ t"); } } } The class BsonDocument { Public string Id {get; set; } Public string Code {get; set; } Public string Codename {get; set; } } The class BsonDocumentComparer: IEqualityComparer { Public Boolean Equals ( BsonDocument x, BsonDocument y ) { Return x.I d==y.I d & amp; & X.C ode==y.C ode; } Public int GetHashCode ( BsonDocument obj ) { Unchecked { Var hashCode=(obj Id!=null? Obj. Id. GetHashCode () : 0); HashCode=(hashCode * 397) ^ (obj Code!=null? Obj. Code. GetHashCode () : 0); Return hashCode; } } } } Output: Id: 1 code: No. 1 Codename: zhang Id: 2 code: No. 2 Codename: li si Id: 3 code: No. 3 Codename: fifty Id: 4 code: No. 4 Codename: Wu Tiezhu