//===================================OrderBy================================== //==unstable== This means that the elements are not preserved when this operator //is called. The order by operator accepts and input sequence, that returns a // key with each element and an ordered output sequence. //===================================Prototype================================ // // public static IOrderedEnumerable<T> OrderBy<T, K>( // this IEnumerable<T> source, // Func<T, K> keySelector) // where // K : IComparable<K>; // //===================================Sumary=================================== //in this prototype an input source sequence is passed into the orderBy operator //along with a keySelector method delegate.This returns an object, upon enumerator //returns the input sequence and passes a key with each element, ordering the //output by the key selector. //============================================================================= //====================================Prototype================================ // // public static IOrderedEnumerable<T> OrderBy<T, K>( // this IEnumerable<T> source, // Func<T, K> keySelector, // IComparer<K> comparer); // //=====================================Summary================================= //This is the same as the first one except is allows for a comparer object to //be passed. //============================================================================ public static void OrderByNameLength() { Presidents_Array _Array = new Presidents_Array(); var orderby = _Array.presidents .OrderBy(s => s.Length); foreach (var x in orderby) { Console.WriteLine(x); } }
//==================================ThenBy================================ //This operator accepts an IorderedEnumerable Object, to be ordered based //the key Selector method. //===================================Prototype================================ // //public static IOrderedEnumerable<T> ThenBy<T, K>( //this IOrderedEnumerable<T> source, //Func<T, K> keySelector) //where //K : IComparable<K>; // //===================================Sumary=================================== //In this prototype of the ThenBy operator, an ordered input sequence of type //IOrderedEnumerable<T> is passed into the ThenBy operator along with a keySelector method //delegate. The keySelector method is passed an input element of type T and will return the field within //the element that is to be used as the key value, of type K, for the input element.Types T and K may be the //same or different types.The value returned by the keySelector method must implement the //IComparable interface. The ThenBy operator will order the input sequence in ascending order based on //those returned keys //============================================================================= public static void OrderByThenBy() { Presidents_Array presidents_Array = new Presidents_Array(); IEnumerable <string> items = presidents_Array.presidents .OrderBy(s => s.Length) .ThenBy(s => s); foreach (string item in items) { Console.WriteLine(item); } }
public static void SkipUntilReachesThreeOr() { Presidents_Array presidents_Array = new Presidents_Array(); IEnumerable <string> skips = Initial_Get_Employee_Array_List.shared_Employee_Classes .SkipWhile((p, i) => p.firstName.Length < 10 && i < 3) .Select(p => p.firstName); IEnumerable <string> test = presidents_Array.presidents .Where((c, i) => (i % 2) == 0);//odd index. foreach (var x in test) { Console.WriteLine(x); } }
public static void ConsonentsVowelRatio() { Presidents_Array _Array = new Presidents_Array(); Comparer_Vowel_ConstantRatio _ConstantRatio = new Comparer_Vowel_ConstantRatio(); IEnumerable <string> namesByVToCRatio = _Array.presidents .OrderBy((s => s), _ConstantRatio); foreach (string item in namesByVToCRatio) { int vCount = 0; int cCount = 0; _ConstantRatio.GetVowlConstantCount(item, ref vCount, ref cCount);//gets number of vowels for two strings, and returns the ratio and the comparer number double dRatio = (double)vCount / (double)cCount; Console.WriteLine($"{item} -- {dRatio} -- {vCount} : {cCount}"); } }
public static void ThenByVowelRatio() { Presidents_Array presidents = new Presidents_Array(); Comparer_Vowel_ConstantRatio comparer_Vowel = new Comparer_Vowel_ConstantRatio(); IEnumerable <string> namesByRatio = presidents.presidents .OrderBy(n => n.Length) .ThenBy((s => s), comparer_Vowel); foreach (string item in namesByRatio) { int vCount = 0; int cCount = 0; comparer_Vowel.GetVowlConstantCount(item, ref vCount, ref cCount); double dRatio = (double)vCount / (double)cCount; Console.WriteLine($"{item} - {vCount} - {cCount}"); } }
public static void Reverse() { Presidents_Array presidents = new Presidents_Array(); var reverse = presidents.presidents .Reverse();//Wow }