C#: how do you check lists are the same size & same elements?

后端 未结 6 1407
一整个雨季
一整个雨季 2021-02-06 12:18

There are two lists of string

List A;
List B;

What is the shortest code you would suggest to check that A.Count ==

6条回答
  •  醉话见心
    2021-02-06 12:30

    How about a simple loop?

    private bool IsEqualLists(List A, List B)
    {
        for(int i = 0; i < A.Count; i++)
        {
            if(i < B.Count - 1) {
                return false; }
            else 
            {
                if(!String.Equals(A[i], B[i]) {
                    return false;
                }
            }
        }
        return true;
    }
    

提交回复
热议问题