Skip to content

Instantly share code, notes, and snippets.

@miya2000
Last active December 15, 2015 08:29
Show Gist options
  • Save miya2000/5231424 to your computer and use it in GitHub Desktop.
Save miya2000/5231424 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace QueryTest
{
[TestClass]
public class QueryTest
{
[TestMethod]
public void Test1()
{
var r =
from n in 1
from o in n * 10
from p in o * 10
from q in p * 10
select n + o + p + q;
r.Is(1111);
var rr = 1
.SelectMany(n => n * 10, (n, o) => new { n, o })
.SelectMany(no => no.o * 10, (no, p) => new { no, p })
.SelectMany(nop => nop.p * 10, (nop, q) => nop.no.n + nop.no.o + nop.p + q);
rr.Is(1111);
}
}
public static class Ex
{
public static U Select<T, U>(this T x, Func<T, U> f)
{
return f(x);
}
public static V SelectMany<T, U, V>(this T x, Func<T, U> f, Func<T, U, V> g)
{
return g(x, f(x));
// こっちの方がわかりやすい?
//return g(x, x.Select(f));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment