Skip to content

Instantly share code, notes, and snippets.

@jhollingworth
Created June 21, 2010 15:39
Show Gist options
  • Save jhollingworth/447033 to your computer and use it in GitHub Desktop.
Save jhollingworth/447033 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Collections.Generic;
namespace managers
{
class MainClass
{
class Employee
{
public string Name {
get;
set;
}
}
class Manager : Employee
{
}
class EmployeeCollection : List<Employee>
{
private bool IsAManager(Employee e)
{
return e is Manager;
}
public Manager[] GetAllManagers()
{
return FindAll(IsAManager).Cast<Manager>().ToArray();
}
}
public static void Main (string[] args)
{
var employees = new EmployeeCollection();
employees.Add(new Employee { Name = "Employee 1" });
employees.Add(new Manager { Name = "Manager 1" });
employees.Add(new Manager { Name = "Manager 2" });
foreach(var manager in employees.GetAllManagers())
{
Console.WriteLine(manager.Name);
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment