Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I hate technical books that try to sound young...

I hate technical books that try to sound young...

Scheduled Pinned Locked Moved The Lounge
csharptutoriallinqquestionlearning
40 Posts 16 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Abhinav S

    OriginalGriff wrote:

    Technically the use of "var" in the first example makes it an anonymous type

    Nope. It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code compiles. A var need not always be neccesarily attached with annonymous types. E.g.

    string[] words = { "apple", "strawberry", "grape", "peach", "banana" };
    var wordQuery = from word in words
    where word[0] == 'g'
    select word;

    Here we already know wordQuery is going to be of type IEnumerable and var need not be used. IEnumerable wordQuery will work just as well. 1. Apologies for posting code here but I could'nt help it. 2. Thanks for making me do some reading on this. 3. As Nish said, I see what you mean here. But I had to post this, I had to. :)

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #13

    :thumbsup: 5! I'm always open to correction. Especially when its stuff I'm trying to learn. Think I'll keep looking for a rather more accurate book. :sigh:

    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    N 2 Replies Last reply
    0
    • N Nish Nishant

      Abhinav S wrote:

      It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code exectues.

      That's not fully correct. The variable type is known at compile time. It just saves you some typing :-)

      Regards, Nish


      Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #14

      Fixed! :)

      The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

      N 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        :thumbsup: 5! I'm always open to correction. Especially when its stuff I'm trying to learn. Think I'll keep looking for a rather more accurate book. :sigh:

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #15

        OriginalGriff wrote:

        I'm always open to correction.

        Abhinav was not 100% right. Please read the corrections to his correction too :-)

        Regards, Nish


        Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

        A 1 Reply Last reply
        0
        • A Abhinav S

          Fixed! :)

          The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #16

          Thank you.

          Regards, Nish


          Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            :thumbsup: 5! I'm always open to correction. Especially when its stuff I'm trying to learn. Think I'll keep looking for a rather more accurate book. :sigh:

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #17

            Well he fixed his post, so it's all good now :-)

            Regards, Nish


            Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

            1 Reply Last reply
            0
            • N Nish Nishant

              OriginalGriff wrote:

              I'm always open to correction.

              Abhinav was not 100% right. Please read the corrections to his correction too :-)

              Regards, Nish


              Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

              A Offline
              A Offline
              Abhinav S
              wrote on last edited by
              #18

              Nishant Sivakumar wrote:

              Abhinav was not 100% right. Please read the corrections to his correction too

              I need a beer... :)

              The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

              N N 2 Replies Last reply
              0
              • A Abhinav S

                Nishant Sivakumar wrote:

                Abhinav was not 100% right. Please read the corrections to his correction too

                I need a beer... :)

                The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #19

                Thanks again for fixing it :-) You don't want newbies who may encounter it in future to go away with wrong info. Good work! :thumbsup:

                Regards, Nish


                Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

                A 1 Reply Last reply
                0
                • N Nish Nishant

                  Thanks again for fixing it :-) You don't want newbies who may encounter it in future to go away with wrong info. Good work! :thumbsup:

                  Regards, Nish


                  Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

                  A Offline
                  A Offline
                  Abhinav S
                  wrote on last edited by
                  #20

                  Nishant Sivakumar wrote:

                  You don't want newbies who may encounter it in future to go away with wrong info

                  Good point.

                  The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

                  1 Reply Last reply
                  0
                  • A Abhinav S

                    Nishant Sivakumar wrote:

                    Abhinav was not 100% right. Please read the corrections to his correction too

                    I need a beer... :)

                    The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

                    N Offline
                    N Offline
                    Nagy Vilmos
                    wrote on last edited by
                    #21

                    Abhinav S wrote:

                    I need a beer...

                    ...again. It is rude to stop at one, the others may think you don't like them.


                    Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre

                    A 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      I decided it was time I read up on LINQ: never really used it, time I learnt. So, I have a quick look for a book. Amazon: Sams LINQ Unleashed for C#. Lets have a quick look "Surprise me" "check out Wikipedia; Wikipedia is wicked cool at providing detailed facts" Hmmm. Wicked cool? And a code fragment to illustrate how wonderfull anonymous types are:

                             var request = HttpWebRequest.Create(string.Format(url, stock));
                              using (var response = request.GetResponse())
                                  {
                                  using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                      {
                                      return (reader.ReadToEnd());
                                      }
                                  }
                      

                      I hate that. Why use an example where it is actually clearer if you don't use anonymous types?

                              WebRequest request = HttpWebRequest.Create(string.Format(url, stock));
                              using (WebResponse response = request.GetResponse())
                                  {
                                  using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                      {
                                      return (reader.ReadToEnd());
                                      }
                                  }
                      

                      Don't think I'll buy that one...

                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                      A Offline
                      A Offline
                      Anthony Mushrow
                      wrote on last edited by
                      #22

                      It's not the 'wicked cool' that throws me in that statement it the 'detailed facts' Wikipedia is convenient, but not to be relied upon too heavily.

                      My current favourite phrase: I've seen better!

                      -SK Genius

                      Source Indexing and Symbol Servers[^]

                      1 Reply Last reply
                      0
                      • N Nagy Vilmos

                        Abhinav S wrote:

                        I need a beer...

                        ...again. It is rude to stop at one, the others may think you don't like them.


                        Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre

                        A Offline
                        A Offline
                        Abhinav S
                        wrote on last edited by
                        #23

                        Nagy Vilmos wrote:

                        "Drink. Get drunk. Fall over." - P O'H

                        :-D

                        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          I decided it was time I read up on LINQ: never really used it, time I learnt. So, I have a quick look for a book. Amazon: Sams LINQ Unleashed for C#. Lets have a quick look "Surprise me" "check out Wikipedia; Wikipedia is wicked cool at providing detailed facts" Hmmm. Wicked cool? And a code fragment to illustrate how wonderfull anonymous types are:

                                 var request = HttpWebRequest.Create(string.Format(url, stock));
                                  using (var response = request.GetResponse())
                                      {
                                      using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                          {
                                          return (reader.ReadToEnd());
                                          }
                                      }
                          

                          I hate that. Why use an example where it is actually clearer if you don't use anonymous types?

                                  WebRequest request = HttpWebRequest.Create(string.Format(url, stock));
                                  using (WebResponse response = request.GetResponse())
                                      {
                                      using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                          {
                                          return (reader.ReadToEnd());
                                          }
                                      }
                          

                          Don't think I'll buy that one...

                          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                          T Offline
                          T Offline
                          TheGreatAndPowerfulOz
                          wrote on last edited by
                          #24

                          sorry, but type inference makes code clearer, I like the first version better. Why should I have to redeclare the variable's type when newing it? It's easily inferred from the right-side.

                          var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)

                          is better than

                          StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)

                          "If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams "Let me get this straight. You know her. She knows you. But she wants to eat him. And everybody's okay with this?"

                          M OriginalGriffO 2 Replies Last reply
                          0
                          • T TheGreatAndPowerfulOz

                            sorry, but type inference makes code clearer, I like the first version better. Why should I have to redeclare the variable's type when newing it? It's easily inferred from the right-side.

                            var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)

                            is better than

                            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)

                            "If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams "Let me get this straight. You know her. She knows you. But she wants to eat him. And everybody's okay with this?"

                            M Offline
                            M Offline
                            mr_lasseter
                            wrote on last edited by
                            #25

                            I agree with you, but it's like arguing about how your favorite color is better than someone else's.

                            Mike Lasseter

                            1 Reply Last reply
                            0
                            • N Nish Nishant

                              Abhinav S wrote:

                              It makes the varible implicity typed i.e. the variable knows nothing about what it will be until the code exectues.

                              That's not fully correct. The variable type is known at compile time. It just saves you some typing :-)

                              Regards, Nish


                              Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

                              M Offline
                              M Offline
                              Mark_Wallace
                              wrote on last edited by
                              #26

                              Nishant Sivakumar wrote:

                              That's not fully correct. The variable type is known at compile time.

                              Real men don't compile code; they just put it straight into production.

                              I wanna be a eunuchs developer! Pass me a bread knife!

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                I decided it was time I read up on LINQ: never really used it, time I learnt. So, I have a quick look for a book. Amazon: Sams LINQ Unleashed for C#. Lets have a quick look "Surprise me" "check out Wikipedia; Wikipedia is wicked cool at providing detailed facts" Hmmm. Wicked cool? And a code fragment to illustrate how wonderfull anonymous types are:

                                       var request = HttpWebRequest.Create(string.Format(url, stock));
                                        using (var response = request.GetResponse())
                                            {
                                            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                                {
                                                return (reader.ReadToEnd());
                                                }
                                            }
                                

                                I hate that. Why use an example where it is actually clearer if you don't use anonymous types?

                                        WebRequest request = HttpWebRequest.Create(string.Format(url, stock));
                                        using (WebResponse response = request.GetResponse())
                                            {
                                            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                                {
                                                return (reader.ReadToEnd());
                                                }
                                            }
                                

                                Don't think I'll buy that one...

                                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                M Offline
                                M Offline
                                Marc Clifton
                                wrote on last edited by
                                #27

                                OriginalGriff wrote:

                                Sams LINQ Unleashed for C#.

                                Three out of five words are bad for your personal hygiene and will give you brain rot: Sams LINQ Unleashed X| And some studies indicate a forth word, "C#", will lead to early onset of Alzheimer's. Marc

                                My Blog

                                1 Reply Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  I decided it was time I read up on LINQ: never really used it, time I learnt. So, I have a quick look for a book. Amazon: Sams LINQ Unleashed for C#. Lets have a quick look "Surprise me" "check out Wikipedia; Wikipedia is wicked cool at providing detailed facts" Hmmm. Wicked cool? And a code fragment to illustrate how wonderfull anonymous types are:

                                         var request = HttpWebRequest.Create(string.Format(url, stock));
                                          using (var response = request.GetResponse())
                                              {
                                              using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                                  {
                                                  return (reader.ReadToEnd());
                                                  }
                                              }
                                  

                                  I hate that. Why use an example where it is actually clearer if you don't use anonymous types?

                                          WebRequest request = HttpWebRequest.Create(string.Format(url, stock));
                                          using (WebResponse response = request.GetResponse())
                                              {
                                              using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                                                  {
                                                  return (reader.ReadToEnd());
                                                  }
                                              }
                                  

                                  Don't think I'll buy that one...

                                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                  Mike HankeyM Offline
                                  Mike HankeyM Offline
                                  Mike Hankey
                                  wrote on last edited by
                                  #28

                                  Try this one [^] I've tried a couple and this one is the best.

                                  Even a blind squirrel gets a nut occasionally. http://www.hq4thmarinescomm.com[^] [My Site]

                                  OriginalGriffO 1 Reply Last reply
                                  0
                                  • T TheGreatAndPowerfulOz

                                    sorry, but type inference makes code clearer, I like the first version better. Why should I have to redeclare the variable's type when newing it? It's easily inferred from the right-side.

                                    var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)

                                    is better than

                                    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)

                                    "If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams "Let me get this straight. You know her. She knows you. But she wants to eat him. And everybody's okay with this?"

                                    OriginalGriffO Offline
                                    OriginalGriffO Offline
                                    OriginalGriff
                                    wrote on last edited by
                                    #29

                                    I disagree. It is lazy, and it shows you don't care about what is being returned. If you explicitly type it then you know exactly what it is and what you can do with it. It's the difference between and ArrayList and a List<T> and I thought that was sorted a long time ago :laugh:

                                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                    1 Reply Last reply
                                    0
                                    • Mike HankeyM Mike Hankey

                                      Try this one [^] I've tried a couple and this one is the best.

                                      Even a blind squirrel gets a nut occasionally. http://www.hq4thmarinescomm.com[^] [My Site]

                                      OriginalGriffO Offline
                                      OriginalGriffO Offline
                                      OriginalGriff
                                      wrote on last edited by
                                      #30

                                      Cheers! I'll have a look...

                                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."

                                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                      1 Reply Last reply
                                      0
                                      • N Nish Nishant

                                        Uhm I am confused, there are no anonymous types used in either code snippet! :confused:

                                        Regards, Nish


                                        Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #31

                                        It's the var keyword, and it's in the first snippet...

                                        - Bits and Bytes Rules! 10(jk)

                                        N 1 Reply Last reply
                                        0
                                        • L Lost User

                                          It's the var keyword, and it's in the first snippet...

                                          - Bits and Bytes Rules! 10(jk)

                                          N Offline
                                          N Offline
                                          Nish Nishant
                                          wrote on last edited by
                                          #32

                                          I guess you did not read the other responses in this thread. :rolleyes:

                                          Regards, Nish


                                          Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

                                          A 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups