Skip to content

Instantly share code, notes, and snippets.

@jtrindade
Created May 5, 2016 20:03
Show Gist options
  • Select an option

  • Save jtrindade/807c4c50499bcfb55f27187a01a1ba61 to your computer and use it in GitHub Desktop.

Select an option

Save jtrindade/807c4c50499bcfb55f27187a01a1ba61 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public static class Enumerating
{
class Student
{
public int Number { get; set; }
public string Name { get; set; }
public bool HasQuit { get; set; }
public int Grade { get; set; }
}
static List<Student> students = new List<Student>()
{
new Student { Number = 1111, Name = "Afonso", HasQuit = false, Grade = 16 },
new Student { Number = 2222, Name = "Sancho", HasQuit = true },
new Student { Number = 3333, Name = "Dinis", HasQuit = false, Grade = 13 },
new Student { Number = 4444, Name = "Pedro", HasQuit = false, Grade = 17 },
new Student { Number = 5555, Name = "Fernando", HasQuit = true },
};
static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
{
foreach (T item in items) action(item);
}
static void Show(IEnumerable<Student> data)
{
data.Where(s => !s.HasQuit).OrderBy(s => s.Grade).Select(s => s.Name).ForEach(Console.WriteLine);
}
public static void Main(string[] args)
{
Show(students);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment