1: protected bool ItemsListIsTheSame(OrderItemList orderItemList, ProductItemList productItemList)
2: {
3: if(orderItemList == null || productItemList == null)
4: return false;
5:
6: bool result = false;
7:
8: // Initialize array length to the generic list sizes
9: int[] productItemIDs = new int[productItemList.Count];
10: int[] orderItemIDs = new int[orderItemList.Count];
11:
12: // loop through generic lists & get the list of ItemIDs (int)
13: for (int i = 0; i < orderItemList.Count; i++)
14: {
15: productItemIDs[i] = orderItemList[i].ItemID;
16: }
17:
18: for (int i = 0; i < productPersList.Count; i++)
19: {
20: orderItemIDs[i] = productItemList[i].Id;
21: }
22:
23: if(productItemIDs == null || orderItemIDs == null)
24: return false;
25:
26: // sort & compare each array of IDs
27: if (productItemIDs.Length == orderItemIDs.Length)
28: {
29: result = true;
30: Array.Sort(productItemIDs);
31: Array.Sort(orderItemIDs);
32:
33: // note: do not perform a nested loop here, it would be inefficient
34: for (int i = 0; i < productItemIDs.Length; i++)
35: {
36: if (orderItemIDs[i] != productItemIDs[i])
37: result = false;
38: }
39: }
40:
41: return result;
42: }