TrimArray() simplification
[NovacoinLibrary.git] / Novacoin / IListExtensions.cs
1 \feffusing System.Collections.Generic;
2 using System.Diagnostics.Contracts;
3
4 namespace Novacoin
5 {
6     static class IListExtensions
7     {
8         public static void Swap<T>(
9             this IList<T> list,
10             int firstIndex,
11             int secondIndex
12         )
13         {
14             Contract.Requires(list != null);
15             Contract.Requires(firstIndex >= 0 && firstIndex < list.Count);
16             Contract.Requires(secondIndex >= 0 && secondIndex < list.Count);
17             if (firstIndex == secondIndex)
18             {
19                 return;
20             }
21             T temp = list[firstIndex];
22             list[firstIndex] = list[secondIndex];
23             list[secondIndex] = temp;
24         }
25     }
26 }