There is a lot of code to enter in this chapter, but it's mechanical. First, we will create an array, so enter the following between the curly braces under the line beginning with protected void Button1_Click...
:
IEnumerable<int> scores = new int[] { 45, 98, 99, 78, 89, 87, 77, 67, 71, 81 };
Here, IEnumerable
is the data type and scores
is the name of the array. It doesn't matter what values you put into the array.
Now, first we will find an average of this list. So, enter the following next:
var goodStudentAverage = (from score in scores where score >= 90 select score).Average();
We will select students who score 90
or above. Imagine, those are the semester grades for several students. So, in the preceding line, we're saying where the score is >=90
, select that score. This is a query that you can write in a single line. In this context, score
is the range variable, scores
is the array, and the condition that selects is where score=...