2 using System.Collections.Generic;
18 public static double Min(
this IEnumerable<double> values )
20 double min =
double.PositiveInfinity;
22 foreach ( var value
in values )
24 if ( value < min ) min = value;
35 public static double Max(
this IEnumerable<double> values )
37 double max =
double.NegativeInfinity;
39 foreach ( var value
in values )
41 if ( value > max ) max = value;
52 public static double Average(
this IEnumerable<double> values )
57 foreach ( var value
in values )
73 public static Vector Average(
this IEnumerable<Vector> values )
75 double xsum = 0, ysum = 0;
78 foreach ( var value
in values )
85 return new Vector( xsum / count, ysum / count );
102 List<TOutput> outList =
new List<TOutput>();
104 foreach ( TInput item
in items )
106 outList.Add( converter( item ) );
112 public static List<T>
FindAll<T>(
this List<T> items, Predicate<T> pred )
116 List<T> outList =
new List<T>();
118 foreach ( var item
in items )
134 for (
int i = 0; i < items.Count; i++ )
136 if ( pred( items[i] ) )
144 public static void RemoveAll<T>(
this List<T> items, Predicate<T> pred )
148 foreach ( var item
in items.FindAll( pred ) )
150 items.Remove( item );
154 public static T Find<T>(
this List<T> items, Predicate<T> pred )
159 return items.Find( pred );
161 foreach ( var item
in items )
176 return Array.Find( array, pred );
178 for (
int i = 0; i < array.Length; i++)
180 if ( pred( array[i] ) )
188 public static IEnumerable<K>
FindAll<K,V>(
this Dictionary<K,V>.KeyCollection keys, Predicate<K> pred )
190 for (
int i = 0; i < keys.Count; i++ )
192 K key = keys.ElementAt( i );
193 if ( pred( key ) ) yield
return key;
static IEnumerable< TOutput > ConvertAll< TInput, TOutput >(this IEnumerable< TInput > items, Converter< TInput, TOutput > converter)
Muuntaa kokoelman tietyn tyyppisiä olioita kokoelmaksi toisen tyyppisiä olioita.
static double Min(this IEnumerable< double > values)
Laskee minimin.
static double Max(this IEnumerable< double > values)
Laskee maksimin.
static int FindLastIndex< T >(this List< T > items, Predicate< T > pred)
static double Average(this IEnumerable< double > values)
Laskee keskiarvon.
Apufunktioita listojen ja muiden tietorakenteiden käyttöön.
static T ArrayFind< T >(T[] array, Predicate< T > pred)
static void RemoveAll< T >(this List< T > items, Predicate< T > pred)
static List< T > FindAll< T >(this List< T > items, Predicate< T > pred)
static IEnumerable< K > FindAll< K, V >(this Dictionary< K, V >.KeyCollection keys, Predicate< K > pred)
static T Find< T >(this List< T > items, Predicate< T > pred)