Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Auxiliary/ListExtensions.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: 890 bytes
Line 
1using System;
2using System.Collections.Generic;
3
4namespace Microsoft.Research.DynamicDataDisplay
5{
6  internal static class ListExtensions
7  {
8    /// <summary>
9    /// Gets last element of list.
10    /// </summary>
11    /// <typeparam name="T"></typeparam>
12    /// <param name="list"></param>
13    /// <returns></returns>
14    internal static T GetLast<T>(this List<T> list)
15    {
16      if (list == null) throw new ArgumentNullException("list");
17      if (list.Count == 0) throw new InvalidOperationException(Strings.Exceptions.CannotGetLastElement);
18
19      return list[list.Count - 1];
20    }
21
22    internal static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
23      if (action == null)
24        throw new ArgumentNullException("action");
25      if (source == null)
26        throw new ArgumentNullException("source");
27
28      foreach (var item in source)
29      {
30        action(item);
31      }
32    }
33  }
34}
Note: See TracBrowser for help on using the repository browser.