fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. abstract class Customer
  5. {
  6. public int id;
  7. public string name;
  8. public double balance;
  9. }
  10.  
  11. class NormalCustomer: Customer
  12. {
  13. }
  14.  
  15. class SubscriberCustomer:Customer
  16. {
  17. public int LandMinutes;
  18. public int MobileMinutes;
  19. }
  20.  
  21. public class Test
  22. {
  23. public static void Main()
  24. {
  25. Customer[] customers = new Customer[5];
  26. customers[0]=new NormalCustomer();
  27. customers[1] = new NormalCustomer();
  28. customers[2] = new SubscriberCustomer();
  29. customers[3] = new NormalCustomer();
  30. customers[4] = new SubscriberCustomer();
  31.  
  32. var groupedCustomers = customers.GroupBy(c => c.GetType()).ToList();
  33.  
  34. foreach(var type in groupedCustomers)
  35. {
  36. Console.WriteLine(type.Key.Name + ", count: " + type.Count());
  37. }
  38. }
  39. }
Success #stdin #stdout 0.06s 24192KB
stdin
Standard input is empty
stdout
NormalCustomer, count: 3
SubscriberCustomer, count: 2