Skip to content

Instantly share code, notes, and snippets.

@zs40x
Last active April 12, 2016 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zs40x/f1fc2c724a2c2ea973ef855e18135d15 to your computer and use it in GitHub Desktop.
Save zs40x/f1fc2c724a2c2ea973ef855e18135d15 to your computer and use it in GitHub Desktop.
class Person
{
public int Age { get; }
public string Name { get; }
public Person(int age, string name)
{
this.Age = age;
this.Name = name;
}
public override string ToString()
{
return $"{ Name }: { Age }";
}
}
public class Program
{
public static void Main(string[] args)
{
InstanceSubsetExampe();
}
private static void InstanceSubsetExampe()
{
var persons = new List<Person>()
{
new Person(15, "Carl"),
new Person(20, "Dan"),
new Person(25, "Mitchell")
};
foreach (var adultPerson in GetAdults(persons))
{
Console.WriteLine(adultPerson);
}
}
private static IEnumerable<Person> GetAdults(IEnumerable<Person> persons)
{
foreach (var person in persons)
{
if(person.Age >= 18)
{
yield return person;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment