Changeset 17225 for branches/2521_ProblemRefactoring/HeuristicLab.Common/3.3/EnumerableExtensions.cs
- Timestamp:
- 08/29/19 13:53:26 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Common/3.3/EnumerableExtensions.cs
r16723 r17225 26 26 namespace HeuristicLab.Common { 27 27 public static class EnumerableExtensions { 28 public static T[,] ToMatrix<T>(this IEnumerable<IEnumerable<T>> source) { 29 if (source == null) throw new ArgumentNullException("source"); 30 if (!source.Any()) return new T[0, 0]; 31 32 int firstDimension = source.Count(); 33 int secondDimension = source.First().Count(); 34 var result = new T[firstDimension, secondDimension]; 35 36 int i = 0; 37 int j = 0; 38 foreach (var row in source) { 39 j = 0; 40 foreach (var element in row) { 41 result[i, j] = element; 42 j++; 43 } 44 if (j != secondDimension) throw new InvalidOperationException("All enumerables must be of the same length."); 45 i++; 46 } 47 48 return result; 49 } 50 51 28 52 /// <summary> 29 53 /// Selects all elements in the sequence that are maximal with respect to the given value.
Note: See TracChangeset
for help on using the changeset viewer.