source contains no elements. Remarks The Max(IEnumerable<Double>) method uses the Double implementation of IComparable<T> to compare values. In Visual Basic query expression syntax, an Aggregate Into Max() clause translates to an invocation of Max. See also Aggregate Clause (Visual Basic) Appli...
Max Finds the maximum number of a sequence of numbers Sum Sums the numbers in a sequence Concatenation Concat Concatenates two sequences into one sequence Conversion Cast Casts elements in a sequence to a given type OfType Filters elements in a sequence of a given type ToArray Returns an ...
sourcecontains no elements. Examples The following code example demonstrates how to useMax<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)to determine the maximum value in a sequence of projected values. C# classPet{publicstringName {get;set; }publicintAge {get;set; ...
下例示範如何建立名為AlternateElements的擴充方法,傳回集合中的每隔個項目,從第一個項目開始。 C# // Extension method for the IEnumerable<T> interface.// The method returns every other element of a sequence.publicstaticIEnumerable<T> AlternateElements<T>(thisIEnumerable<T> source) {intindex =0;for...
max($func = null) // Returns the maximum item value according to $func. min($func = null) // Returns the minimum item value according to $func orderBy($func) // Sorts the elements in ascending order according to a key provided by $func. orderByDescending($func) // Sorts the ...
All elements starting from first element less than its position: 1 3 9 8 6 7 2 0 LINQ - Ordering Operators linq28: OrderBy - Simple 1 //c# public void Linq28() { string[] words = { "cherry", "apple", "blueberry" }; var sortedWords = from w in words orderby w select w;...
下例示範如何建立名為AlternateElements的擴充方法,傳回集合中的每隔個項目,從第一個項目開始。 C# // Extension method for the IEnumerable<T> interface.// The method returns every other element of a sequence.publicstaticIEnumerable<T> AlternateElements<T>(thisIEnumerable<T> source) {int...
InvalidOperationException source contains no elements. Remarks The Max<TSource>(IEnumerable<TSource>, Func<TSource, Decimal>) method uses the Decimal implementation of IComparable<T> to compare values. You can apply this method to a sequence of arbitrary values if you provide a functio...
If there are no items, First and Single will throw an InvalidOperationException with the message “Sequence contains no elements.” FirstOrDefault and SingleOrDefault protect you from the exception by returning the default, which is generally a null (Nothing in VB). Additionally, if you use ...
When you start playing with LINQ queries over sequences of elements (e.g. getting min / max value for enumerable source) sooner or later you will come across this one -- the InvalidOperationException (“Sequence contains no elements”). ...