Simple List Comparison question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chickenman
    New Member
    • Jul 2008
    • 4

    Simple List Comparison question

    First time poster here so hopefully will not get flamed too badly ;) I am trying to teach myself C# and am using VS2005 right now on XP.

    Here is the code snippet I have after doing a streamreader:

    Code:
    string[] llarray = line.Split(',');
    string labelInfo = llarray[1].ToString() + "-" + llarray[2].ToString();
    string completelabelInfo = llarray[1].ToString() + "-" + llarray[2].ToString() + "," + fileName;
    if (masterLabelInfo.Contains(labelInfo))
    {
        duplicateFileNames.Add(completelabelInfo);
    }
    else
    {
        masterLabelInfo.Add(labelInfo);
    }
    Basically it reads a file and if the first list does not contain the file then it sends it to the original list. If it does contain the value then it goes to the duplicate list. This part works and will give me the duplicate filenames.

    My question is this:

    How would I go about retrieving the value in the master list that they are duplicating? I am about google'd out. I was thinking of some sort of search in the list, but am not too familiar with that process yet.

    Any help is appreciated. (no comments on the god-awful coding structure ;) I am a noob and it will get better I hope! )

    Patrick

    (Hope I posted everything correctly.)
    Last edited by Curtis Rutland; Jul 29 '08, 04:15 PM. Reason: Fixed up your code formatting a little bit :)
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Couldn't you just look in the duplicate list and see all the names they are duplicating?

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Correct me if I'm wrong but is
      Code:
      completelabelInfo = labelInfo + ", " + fileName;
      And you want to find the labelInfo given a completelabelIn fo?

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Welcome to Bytes!

        Nobody gets flamed here, and if someone tries it, they answer to us (the mods).

        Now, as to your question...what type are your master lists? Are they ArrayLists or string[] or what? You should be able to loop through them, comparing each value to the one you want to check for, and save the index that the duplicate exists on.

        Comment

        • Chickenman
          New Member
          • Jul 2008
          • 4

          #5
          The array's are string[].
          The Master list is List<string>.

          The completeinfo simply has my information I am searching on as well as the UNC to the file that it corresponds with.

          I am pulling a line out of several files. It will give me the result of say:
          information duplicate1, then the UNC and filename that is associated with it
          information duplicate2, then the UNC and filename of the second file.

          I might just be missing a piece of code for checking it against the masterlist if it turns out to be a duplicate.

          I am not sure that has anything that might help :(

          Thanks for the quick response!
          Last edited by Chickenman; Jul 29 '08, 04:32 PM. Reason: clarification

          Comment

          Working...