日期:2014-05-16 浏览次数:20468 次
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<ClassA> listA = new List<ClassA>()
{
new ClassA(){ Aid="001"},
new ClassA(){ Aid="002"},
};
List<ClassB> listB = new List<ClassB>()
{
new ClassB(){ Bid="1" ,Aid="001"},
new ClassB(){ Bid="2" ,Aid="002"},
new ClassB(){ Bid="3" ,Aid="003"},
};
//写法1
var result = from a in listA
from b in listB
where a.Aid == b.Aid
select new { b.Aid, b.Bid };
foreach (var item in result)
{
Console.WriteLine("{0},{1}", item.Aid, item.Bid);
}
//写法2
var result1 = listA.SelectMany(x => from p in listB where p.Aid == x.Aid select new { p.Aid, p.Bid });
&nbs