Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/ArrayExtensions.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 832 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Microsoft.Research.DynamicDataDisplay.Charts;
6
7namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary
8{
9  internal static class ArrayExtensions
10  {
11    internal static T Last<T>(this T[] array) {
12      return array[array.Length - 1];
13    }
14
15    internal static T[] CreateArray<T>(int length, T defaultValue)
16    {
17      T[] res = new T[length];
18      for (int i = 0; i < res.Length; i++)
19      {
20        res[i] = defaultValue;
21      }
22      return res;
23    }
24
25    internal static IEnumerable<Range<T>> GetPairs<T>(this IList<T> array)
26    {
27      if (array == null)
28        throw new ArgumentNullException("array");
29
30      for (int i = 0; i < array.Count - 1; i++)
31      {
32        yield return new Range<T>(array[i], array[i + 1]);
33      }
34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.