- using System;
- using System.Collections.Generic;
- using System.Text;
- public static class myEnumerable
- {
- public static IEnumerable<S> Select<T, S>(
- this IEnumerable<T> source, Func<T, S> selector)
- {
- foreach (T item in source)
- {
- yield return selector(item);
- }
- }
- }
- class PetOwner
- {
- public string Name { get; set; }
- public List<String> Pets { get; set; }
- }
- class ExtensionMethods
- {
- public static void Main()
- {
- PetOwner[] petOwners =
- {
- new PetOwner { Name="Higa, Sidney", Pets = new List<string>{ "Scruffy", "Sam" } },
- new PetOwner { Name="Ashkenazi, Ronen", Pets = new List<string>{ "Walker", "Sugar" } },
- new PetOwner { Name="Price, Vernette", Pets = new List<string>{ "Scratches", "Diesel" } }
- };
- IEnumerable<List<String>> query =petOwners.Select(petOwner => petOwner.Pets);
- foreach (List<String> petList in query)
- {
- foreach (string pet in petList)
- {
- Console.WriteLine(pet);
- }
- Console.WriteLine();
- }
- Console.ReadKey();
- }
- }