tags:

views:

25

answers:

1
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() };

Please tell me dot notation of this query. Thanks.

+2  A: 

The dot notation for a join depends on what follows it and whether or not you've got an "into" clause (for a group join). In this case it would be:

var query = names.GroupJoin(people, n => n, p => p.Name,
                   (n, matching) => new { Name = n, Count = matching.Count() });
  • If you didn't use "into" it would use Join instead of GroupJoin
  • If you had anything other than just "select" afterwards, it would introduce a new transparent identifier to keep "(n, matching)" as a tuple, effectively.
Jon Skeet