snippets / Array compare / Comparaison de tableau

Language: C# - First posted by themadmax on 2008-02-26 17:02 (8 months, 3 weeks)
Link to the snippet: http://www.friendsnippets.org/snippet/194/

Return true for match, else false Retourn true en cas d'egalité sinon false

 1          public static bool compare<T>(ICollection<T> tabA, ICollection<T> tabB) where T : IComparable
2 {
3 System.Diagnostics.Debug.Assert(tabA != null);
4 System.Diagnostics.Debug.Assert(tabB != null);
5
6 if ( tabA.Count != tabB.Count)
7 return false;
8
9 IEnumerator<T> enumA = tabA.GetEnumerator();
10 IEnumerator<T> enumB = tabB.GetEnumerator();
11 while ( enumA.MoveNext() && enumB.MoveNext() )
12 {
13 if ( enumA.Current.CompareTo(enumB.Current) != 0 )
14 return false;
15 }
16 return true;
17 }
In order to post a comment, you should have a friendsnippet account. Please sign-in.

0 comments

Feb '08
  • Return true for match, else false Retourn true en cas d'egalité sinon false