Basics of LINQ II

After a very simple beginning of LINQ let’s continue to play with it more.

In this article, I will try to share some basic methods such as First,Last, Max and Min.

1. Numbers Example:

Let’s create an int array with some numbers and find the first number, last number, first number which is greater then 4, first odd number and number less then 6.

var numbers = new int[] { 2, 3, 4, 5, 6, 7, 8, 9 };

 var firstNumber = numbers.First(); // = 2

 var lastNumber = numbers.Last(); // = 9 

 var firstNumberGreaterThenFour = numbers.First(t => t > 4) ; // = 5

 var firstOddNumber = numbers.First(n => n % 2 == 1); // = 3

 var lastNumberLessThanSix = numbers.Last(n => n < 6); // = 5

2. My Friends

In this part, I’ve created a custom class called Friend and made a list of my friend with their age. Continue reading

#first, #last, #linq-2, #max, #min