2010-09-13 61 views
3
string[] names = { "Burke", "Connor", "Frank", 
    "Albert", "George", "Harris", "David" }; 

peoples[] people = { 
        new peoples("Connor",20), 
        new peoples("John",22), 
        new peoples("Merry",33), 
        new peoples("Frank",65), 
        new peoples("Frank",34), 
        new peoples("George",19) 
       }; 

var query = from n in names 
      join p in people on n equals p.Name into matching 
      select new { Name = n, Count = matching.Count() }; 

請告訴我這個查詢的點符號。 謝謝。點符號相當於JOIN

回答

2

連接的點符號取決於它後面的內容以及是否有「into」子句(用於組連接)。在這種情況下,這將是:

var query = names.GroupJoin(people, n => n, p => p.Name, 
        (n, matching) => new { Name = n, Count = matching.Count() }); 
  • 如果您沒有使用「到」如果你有比其他任何東西只是「選擇」,將利用Join代替GroupJoin
  • 後,將會引入一個新的透明標識符可以有效地保持「(n,匹配)」爲一個元組。