C# 5.0: More Than Just Async: Listing 3.

How C# 5.0 changes LINQ expressions.

public static void LinqBreak()
{
  var data = new List <IEnumerable <string > >();
  var numbers = new[] {1, 2, 3, 4};
  var strings = new[] {"1", "2", "3", "4"};

  foreach (var number in numbers)
  {
    var result = from s in strings
                   where s == number.ToString()
                   select s;
    data.Add(result);
  }

  foreach (var num in data)
  {
    Console.WriteLine(num.First());
  }
}

About the Author

Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.

comments powered by Disqus

Featured

Subscribe on YouTube