View Full Version : C#: 2 arrays, 1 shorter than the other

03-22-2004, 05:08 AM
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?

03-22-2004, 08:26 AM
Do you want to compare every string with every object:

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):

for (int i = 0; i < objArray.length && i < strArray.length; i++) {
// compare objArray[i] with strArray[i]


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

03-23-2004, 12:01 AM
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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum