Time for action – radio "Lucky Caller" announcement
Suppose you are writing a program for a radio station where you need to find every third name in the array and say "Hi! <Name> You are the Lucky 3rd Caller". So you see in this case, the index of the element currently being projected is of importance. A little change in the Lambda expression used in the previous example, is all it will take to make this happen:
- Copy the following code snippet as a query to LINQPad:
List<int> First100LuckyCallerIndices = new List<int>(); //First lucky third caller's index in the array will be 2. First100LuckyCallerIndices.Add(2); for (int i = 0; i < 100; i++) First100LuckyCallerIndices.Add(First100LuckyCallerIndices.Last() + 3); List<string> nameList1 = new List<string>() ...