Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Generic declaration with var type in LINQ in C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ForgetCode
  7. {
  8. public class MainClass
  9. {
  10. public static void Main()
  11. {
  12. // Load your DB file here
  13. var customerQuery =
  14. from cust in customers
  15. where cust.City == "London"
  16. select cust;
  17.  
  18. foreach (var customer in customerQuery)
  19. {
  20. Console.WriteLine(customer.LastName + ", " + customer.FirstName);
  21. }
  22. }
  23. }
  24. }