2009-10-14 63 views

回答

14
// If you dont want to use a sub query, I would suggest: 

     var result = (
      from f in foos 
      from s in f.MyStrings 
      select s).Distinct(); 

     // Which is absoulutely equivalent to: 

     var theSameThing = foos.SelectMany(i => i.MyStrings).Distinct(); 

     // pick the one you think is more readable. 

我也強烈建議閱讀MSDN上可枚舉擴展方法。這是非常豐富的,有很好的例子!