Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ConsoleApp
- {
- enum Brand
- {
- Nike,
- Adidas,
- Levis
- }
- class Info
- {
- public Brand Brand { get; set; }
- public int Start { get; set; }
- public int End { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var list = new Info[]
- {
- new Info{Brand = Brand.Nike, Start = 0, End = 4},
- new Info{Brand = Brand.Adidas, Start = 0, End = 5},
- new Info{Brand = Brand.Nike, Start = 4, End = 10},
- new Info{Brand = Brand.Levis, Start = 0, End = 3},
- new Info{Brand = Brand.Adidas, Start = 5, End = 8}
- };
- var start = 6;
- var end = 10;
- var result = (
- from item in list
- group item by item.Brand into g
- from subItem in g
- where (subItem.Start <= start && subItem.End >= start) || (subItem.Start <= end && subItem.End >= end)
- select new
- {
- Brand = g.Key,
- Max = g.Max(x => x.End)
- }
- ).Distinct();
- foreach (var item in result.ToList())
- Console.WriteLine("{0} - {1}", item.Brand, item.Max);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement