ListComparer

    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;

    public static class ListComparer
    {
        public static bool ListsEqual(IList list1, IList list2)
        {
            if (list1.Count != list2.Count)
            {
                return false;
            }
            for (int i = 0; i < list1.Count; i++)
            {
                if (list1[i] != list2[i])
                {
                    return false;
                }
            }
            return true;
        }

        public static bool ListsEqual(IList list1, IList list2, ObjectCompareDelegate compare)
        {
            if (list1.Count != list2.Count)
            {
                return false;
            }
            for (int i = 0; i < list1.Count; i++)
            {
                if (!compare(list1[i], list2[i]))
                {
                    return false;
                }
            }
            return true;
        }

        public delegate bool ObjectCompareDelegate(object x, object y);
    }

posted @ 2010-02-15 21:48  我想去长安  阅读(165)  评论(0编辑  收藏  举报