Jump to content

C# compare method help


bluntm
 Share

Recommended Posts

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"

Link to comment
Share on other sites

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;
        }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...