So, you want to retrieve the index of an matching item in an array or a collection and you want to use LINQ.
For example, I want to get the month number given the month name – If I pass 3, I should get March
Of course, you could write your own enum and other stuffs, but there is already an out-of-the-box MonthNames array that we can make use of.
How can we make use of this MonthNames array to get the month name based on the month number?
Using LINQ, its very simple!
The lambda expression (month,index) with 2 parameters gets the index of that item and it is an inbuilt feature in LINQ. The second parameter always refers to the index of that item. It is also not necessary that it should be named index. You can name it anything you want, like this: