10 Replies - 325 Views - Last Post: 04 May 2012 - 03:31 PM Rate Topic: -----

#1 kenryuakuma  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 362
  • Joined: 14-December 08

Temporary Identifier

Posted 04 May 2012 - 11:18 AM

var address = from addr in mailAddress
              where addr.LastIndexOf(".") != -1
              group addr by addr.Substring(addr.LastIndexOf("."))
              into ws
              where ws.Count() > 2
              select ws;



The question is that
according to MSDN, the temporary identifier is ws. However, according to my context book, the ws is a range variable of the new query. The temp identifier seems to be not visible to the end users. It is just the memory allocated in the computer to store the temp result which can be iterated or ranged over by the new ws range variable.

However, MSDN is sometimes criticized for publishing wrong code due to haste.

So just forget above the comments I wrote. So according to your knowledge and experience, is ws a temp identifier or a range variable?

if ws is a temp identifier, how can it be iterated without the range variable? Just don't get it.

This post has been edited by eclipsed4utoo: 04 May 2012 - 11:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Temporary Identifier

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1690
  • View blog
  • Posts: 2,553
  • Joined: 21-June 11

Re: Temporary Identifier

Posted 04 May 2012 - 11:22 AM

What's your question? Why the query doesn't work? Because it doesn't end with a select clause.
Was This Post Helpful? 1
  • +
  • -

#3 kenryuakuma  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 362
  • Joined: 14-December 08

Re: Temporary Identifier

Posted 04 May 2012 - 11:26 AM

MOD EDIT: moving post with question to the top...

This post has been edited by eclipsed4utoo: 04 May 2012 - 11:49 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6447
  • View blog
  • Posts: 23,462
  • Joined: 12-June 08

Re: Temporary Identifier

Posted 04 May 2012 - 11:28 AM

Merging duplicate topics.. FYI you can either edit your original post or just add a reply to it if you botch up making a post.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: Temporary Identifier

Posted 04 May 2012 - 12:03 PM

The range variable is addr and the temporary identifier is ws.
Was This Post Helpful? 0
  • +
  • -

#6 kenryuakuma  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 362
  • Joined: 14-December 08

Re: Temporary Identifier

Posted 04 May 2012 - 12:12 PM

well...Isn't the ws a new range variable of a new query? Since into will create a continuation query, there must be a range variable??? This is what the book is referring to.

If ws is temp, how does it work? confused!!!
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: Temporary Identifier

Posted 04 May 2012 - 12:22 PM

I wouldn't consider ws a range variable because you can't use it on it's own like you could addr. In your code, if you evaluate address, it's some crazy type that isn't useful on it's on.
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1949
  • View blog
  • Posts: 8,672
  • Joined: 29-May 08

Re: Temporary Identifier

Posted 04 May 2012 - 12:33 PM

Both addr and ws are range variables
Was This Post Helpful? 0
  • +
  • -

#9 kenryuakuma  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 362
  • Joined: 14-December 08

Re: Temporary Identifier

Posted 04 May 2012 - 01:51 PM

This is what the MSDN states:

Quote

The into contextual keyword can be used to create a temporary identifier to store the results of a group, join or select clause into a new identifier. This identifier can itself be a generator for additional query commands. When used in a group or select clause, the use of the new identifier is sometimes referred to as a continuation.


It seems to makes sense to regard the new identifier as a variable to store the results of the sequences.

However, according to the example, it is confusing and seems to be a conflict with the statement above.

Quote

The following example shows the use of the into keyword to enable a temporary identifier fruitGroup which has an inferred type of IGrouping. By using the identifier, you can invoke the Count method on each group and select only those groups that contain two or more words.


class IntoSample1
{
    static void Main()
    {

        // Create a data source.
        string[] words = { "apples", "blueberries", "oranges", "bananas", "apricots"};

        // Create the query.
        var wordGroups1 =
            from w in words
            group w by w[0] into fruitGroup
            where fruitGroup.Count() >= 2
            select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };

        // Execute the query. Note that we only iterate over the groups, 
        // not the items in each group
        foreach (var item in wordGroups1)
        {
            Console.WriteLine(" {0} has {1} elements.", item.FirstLetter, item.Words);
        }

        // Keep the console window open in debug mode
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}
/* Output:
   a has 2 elements.
   b has 2 elements.
*/


Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1949
  • View blog
  • Posts: 8,672
  • Joined: 29-May 08

Re: Temporary Identifier

Posted 04 May 2012 - 02:11 PM

It'll help if you understand what the following
var wordGroups1 =
  {from w in words => 
  group w by w[0] } into fruitGroup} =
    where fruitGroup.Count() >= 2
    select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };


gets converting into
var wordGroups1 =
  Enumberable.Select(
    Enumerable.Where( 
      Enumerable.GroupBy(
        words,
        (w) => w[0],
        (w) => w
      ),
      (fruitGroup) => fruitGroup.Count >= 2
    ),
    (fruitGroup) => new { FirstLetter = fruitGroup.Key,
                          Words       = fruitGroup.Count()};
  );


Was This Post Helpful? 0
  • +
  • -

#11 kenryuakuma  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 362
  • Joined: 14-December 08

Re: Temporary Identifier

Posted 04 May 2012 - 03:31 PM

So the fruitGroup is also the range variable for a new query? So just wonder where the temp result is stored at? Within the memory just like what the author of the text book said?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1