bluntm Posted March 2, 2009 Posted March 2, 2009 hi im witting an app that compiles two lists of a custom object called object, the object contains 4 attributes: string name string header string body string passOrFail the first list called List1 contains 40 [can change] objects with all the details filled in e.g name: file header: a file of data body: a file can contain different types of data passOrFail: not yet set yet but will ehter be, pass, fail or no match and the the second list contains the same style of information, what im looking to do is compare the two lists, the second list is larger and will have more data in it. i only need to verify that items in the first list are in the second list. to get a pass all three (name, Header, body) must match. also if the name and body match but the header of the second list == "cant get data" then the result is pass to get a fail the name must match one of the entries in the second list but either the header or body must fail and if the name does not exist in the second list then its "no match" Quote
Ferros Posted March 3, 2009 Posted March 3, 2009 http://www.java2s.com/Tutorial/CSharp/0100...ing-Compare.htm first hit on google. Quote
bluntm Posted March 3, 2009 Author Posted March 3, 2009 Thanks for the reply but, i know how to compare 2 strings, the problem im having is comparing two lists where the first is smaller than the second and the are not in sync my problem is more complex my code so far is shown below the smaller list is the one called mist: public tooltipSupertip comparetooltip(tooltipSupertip mist, List<tooltipSupertip> uex) { // all parts match foreach (tooltipSupertip uexTip in uex) { if (mist.name == uexTip.name && mist.tipHeader == uexTip.tipHeader && mist.tipBody == uexTip.tipBody) { mist.passOrFail = "pass"; return mist; } } // there was no TCID so the tooltip could not be compared foreach (tooltipSupertip uexTip in uex) { if (mist.name.Equals(uexTip.name) && uexTip.tipHeader.Equals("No TCID to get tip Header")) { Log.Comment(mist, "No TCID to compare tooltips!"); mist.passOrFail = "No Match"; return mist; } } // check that the tooltip is in the Uex run int found = 0; foreach (tooltipSupertip uexTip in uex) { if (mist.name.Equals(uexTip.name)) { found++; } } if (found == 0) { mist.passOrFail = "No Match"; return mist; } mist.passOrFail = "fail"; return mist; } Quote
Cthobs Posted March 3, 2009 Posted March 3, 2009 and the the second list contains the same style of information, what im looking to do is compare the two lists, the second list is larger and will have more data in it. i only need to verify that items in the first list are in the second list. Use a pair of embedded for loops. This will give you a chance to test every possible pairing of the two lists. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.