Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2004
    Location
    Illinois
    Posts
    72
    Thanks
    2
    Thanked 0 Times in 0 Posts

    C#: 2 arrays, 1 shorter than the other

    Sorry for all these questions, but I think that I've just came accross the most confusing thing i'll ever see. I have 2 arrays, one array is an array of 21 objects, the other array is an array of strings that are insterted into the array through a String.Split() function. I'm trying to compare the strings in the strings array to a string property in the objects array. I can't use a for statment because both arrays alwasy differ in length. Anyone know how?

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you want to compare every string with every object:
    Code:
    for (int i = 0; i < objArray.length; i++) {
      for (int j = i; j < strArray.length; j++) {
        // compare objArray[i] with strArray[j]
      }
    }
    or compare the strings with their respective object (ie, with the same index in the array):
    Code:
    for (int i = 0; i < objArray.length && i < strArray.length; i++) {
      // compare objArray[i] with strArray[i]
    }
    shmoove

    ps: the code is in Java because I don't know C#, but I imagine it would be rather similar.

  • #3
    New Coder
    Join Date
    Jan 2004
    Location
    Illinois
    Posts
    72
    Thanks
    2
    Thanked 0 Times in 0 Posts
    1 array of strings, with another array of objects, but I want to compare the array of strings with a property(s) of the objects in the array, example

    splitedstringarray with objectsarrya[i].stringproperty


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •