Zeeshan Hirani
-
ThenBy Operator Part 14
ThenBy is one of the ordering query operators available in linq. You can use ThenBy operator with linq to objects, linq to XML and linq to SQL. You will typically use ThenBy operator to do secondary sort. ThenBy operator is used to sort by more than 1 property. When you want to sort initially you would start with using the orderby operator. Since orderby operator returns IOrderderedEnumerable<T>, you cannot reuse the orderby operator again because it can be only used on sequences that implement IEnumerable<T>. This is where the ThenBy operator comes into play. ThenBy operator is an extension method that is available on input sequence that implement IOrderededEnumerable<T> and also returns IOrderedEnumerable<T> which allows you to reuse it multiple times if you want to sort by more than 1 column or property. The prototype of ThenBy operator looks like this
-
OrderBy Operator Part 13
OrderBy is one of the ordering query operators available in linq. In terms of availability, you can use OrderBy query operator with linq to objects, linq to SQL and linq to XML. Unlike many query operators that are only available in method or dot syntax, OrderBy query operator can also be used in query syntax which is sometimes easier to use than method syntax.
-
Union Operator Part 12
Union is one of the set query operators available in linq. It appends 2 input sequences together ensuring that duplicates are removed and returns a single output sequence. The prototype for union operator looks like this
-
Reverse Operator Part 11
Reverse is one of ordering query operator. Reverse operator simply returns the input sequence in the reverse order. It does not effect the elements in the input sequence in any way. The prototype of the reverse operator looks like this
-
SequenceEqual operator Part 10
Sequence operator determines if two sequences are equal to each other.Two collections are considered equal if they have the same number of elements with same values and in present in the same order.
-
Concat Operator Part 9
Concat is one of the set operators available in Linq. When you work with Linq query operators for sometime, you would notice that there are certain query operators that can all perform a certain job but some operators in certain scenario are easier to work with or more efficient in performing the computation that others. Concat operator allows you to join two sequences together into one single output sequence. You can perform the same operation using selectmany or union operator. The selectmany operator has an advantage that it would allow you to join many sequences into one single sequence.Concat supports joining only two collections and therefore you would have to repeat this operation several times to achieve the same result that selectmany operator would give. Union offers the same functionality with little more power. With union, you can get rid of duplicates that is elements that are common in both sequences. Union uses the default EqualityComparer. If this comparer does not suffice you needs, you have an overloaded option to specify you own IEqualityComparer that defines how to compare two elements to identify if there are same or not.
-
SkipWhile Operator Part 8
SkipWhile Operator skips elements based on the delegate condition. It continues to skip the elements as long as the predicate returns true. As soon as it encounters false statement, it returns rest of the elements. The prototype of the skip operator looks like this
-
Skip Operator Part 7
Skip is one of the filtering operators available in linq. Skip operator skips the first count elements and returns rest of the elements in the collection. The prototype of the skip operator looks something like this
-
Take While Operator Part 6
Takewhile is a partitioning operator available in linq. It starts from the beginning of the series and continues to return the elements from the input sequence as long as condition is validating to true. As soon as it hits the first statement that evaluates to false it skips rest of the collection.
-
Take Operator Part 5
Take is one of the filtering operator available in linq. It returns first n number of elements and discards rest of the collection. The prototype of Take operator looks like this