15,745,509 members
See more:
Hi I have two array lists of different sizes. suppose list1 have 4 values and list 2 have two values. My question is "how to check whether list 2 values are present in list1 or not ?
Posted
Jameel VM 21-Jun-13 2:45am
can you post the code of the two array lists?

## Solution 5

Check this. I think you will get your solution.

code:

```ArrayList numList1 = new ArrayList(new int[] { 1, 2, 3, 4});
ArrayList numList2 = new ArrayList(new int[] { 1, 5, 3});

ArrayList numListDiff3 = new ArrayList();
foreach (int listElement in numList1)
{
if (!numList2.Contains(listElement))
{
}
}

foreach (int listElement in numList2)
{
if (!numList1.Contains(listElement))
{
}
}```

Source: http://forums.asp.net/post/3573258.aspx[^]

v2

## Solution 3

Something like this:
C#
```ArrayList list1 = new ArrayList(new int[] {1,2,3,4,5});
ArrayList list2 = new ArrayList(new int[] {1,2,8});
for (int i=0; i<list1.count && i<list2.Count; i++) {
if (!Object.Equals(list1[i], list2[i]))
Console.WriteLine("Different value at index {0}.", i);
}```

v2

## Solution 2

Hi,
I will propose to use Linq to do your operation.
You can find a discussion on this point:
http://stackoverflow.com/questions/9524681/linq-compare-two-lists[^]

Best regards.

## Solution 4

```ArrayList list1 = new ArrayList(new int[] {1,2,3,4,5});

ArrayList list2 = new ArrayList(new int[] {1,2,8});

for (int i=0; i<list1.Count && i<list2.Count; i++)

{

if (!Object.Equals(list1[i], list2[i]))

Console.WriteLine("Different value at index {0}.", i);

}

if (list1.Count > list2.Count)

Console.WriteLine("list1 has more elements than list2.");

if (list2.Count > list1.Count)

Console.WriteLine("list2 has more elements than list1.");

}```