finding/comparing values in arraylists
-
I have two arraylists, each record in each arraylist has the same 2 fields Any ideas what I could code to see if the value of a field in a given row in one arraylist is the same as the value of a field in a row in the the other arraylist?
if (((objectType)firstArr(0)).fieldName == ((objectType)secondArr(0)).fieldName)
{
//etc
} -
if (((objectType)firstArr(0)).fieldName == ((objectType)secondArr(0)).fieldName)
{
//etc
} -
I'm not understanding whats needed for object type my arrays have two fields in each record; ID number and name, both are strings. Also the only extention that the system lets me put after my arraylist name is .GetType (objectType)firstArr(0)).GetType
Replace objectType with the type of object you have stored in the ArrayList, or better yet if you use .NET 2.0 use List rather than ArrayList. So for example, if you have a DataRow stored in the ArrayList, do this: ArrayList arrList1, arrList2; //stuff to instantiate your arraylists if (((DataRow)arrList1[0])[0].ToString() == ((DataRow)arrList2[0])[0].ToString()) { // do stuff } But with Lists do like this: List list1, list2; //stuff to instantiate your lists if (list1[0][0].ToString() == list2[0][0].ToString()) //do stuff