C# Program For Producing a Filtered Sequence of Elements that Contain Only One Property of Given Data
Given a list that contains the details of the students, now we produce a filtered sequence of elements that contain only one property of each Student. So we use the following method of LINQ to solve the given problem:
1. Aggregate() method: This method is used to perform aggregation operations on the values of a collection. In simple words, this method is used to implements a number of operations for each of the elements in the specified collection by keeping the track of the actions that have been done before. For example, the aggregation function is used to calculate the annual rainfall that occurred in 2021 in step with readings collected the entire year. Another example is the product function is used to calculate the product of the values specified in an array.
result = collection.Aggregate((element1, element2) => element1 operation element2);
2. Select clause: The select clause is specifically used to return the IEnumerator collection and this collection holds a number of items that rely on a transformation function. In simple words, we can say that a select operator should be used if the programmer wants to pick or select a single value from the given collection. For a query expression, the select clause what type of values must be selected when a query is made. Note that a query expression is required to be terminated with either a group clause or select clause.
IEnumerable<int> collection =
from element in collection
Here, the collection represents an IEnumerable collection and expression represents a Condition expression.
Example: In this C# program, we are producing a filtered sequence of elements that have only one property of each Student by using the Select Clause LINQ. Also, we are selecting only those elements that satisfy certain conditions. For this purpose, we have used IEnumerable Interface in order to check the condition that the value of the student.Roll_No must be greater than 2. It is possible through iteration over a non-generic collection.
student Query: Mehta Singh