Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created September 24, 2012 07:58
Show Gist options
  • Save masaru-b-cl/3774854 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/3774854 to your computer and use it in GitHub Desktop.
手動でJoinってこういうこと?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var items = new[] {
new { Category = "A", Year = 2012, Param = new[]{ 1, 2, 3}},
new { Category = "A", Year = 2013, Param = new[]{ 4, 5, 6}},
new { Category = "B", Year = 2012, Param = new[]{ 7, 8, 9}},
new { Category = "C", Year = 2013, Param = new[]{ 3, 4, 5}},
};
var rank = new[] {
new { Category = "A", Lv = 4 },
new { Category = "B", Lv = 3 },
new { Category = "C", Lv = 2 },
new { Category = "D", Lv = 1 },
};
var lookup = items.ToLookup(x => x.Category);
var q = rank.Select(x => new { Categoly = x.Category, Lv = x.Lv, Values = lookup[x.Category].Select(y=>y) });
q.Dump();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment