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 1 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.
  • 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
                    • N Nish Nishant

                      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 Offline
                      A Offline
                      Abhinav S
                      wrote on last edited by
                      #33

                      Quite a few of them. ;)

                      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.

                      N 1 Reply Last reply
                      0
                      • A Abhinav S

                        Quite a few of them. ;)

                        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.

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

                        Yeah, the number of C# developers who don't understand the var keyword is shocking!

                        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

                          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."

                          E Offline
                          E Offline
                          Edbert P
                          wrote on last edited by
                          #35

                          var is used in LINQ extensively so you do not have to create a new class for each LINQ statement that returns a subset of properties from the object being queried(or a new combination from several objects) , e.g.

                          var result = from employee in employees
                          select new { employee.Id, employee.Name}

                          This way you don't have to create a new class containing only Id and Name, but you still get the benefit of strongly-typed LINQ result, i.e. you can do

                          result.Id

                          and

                          result.Name

                          We can all discuss about benefit of var vs. declaring a variable type explicitly (i.e. var dataReader against SqlDataReader dataReader) till the cows come home and won't go anywhere. I think the benefit of var in this case is very small (if any), and if people don't want to use var for this I'm fine about it.

                          "A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin Edbert Sydney, Australia

                          T 1 Reply Last reply
                          0
                          • E Edbert P

                            var is used in LINQ extensively so you do not have to create a new class for each LINQ statement that returns a subset of properties from the object being queried(or a new combination from several objects) , e.g.

                            var result = from employee in employees
                            select new { employee.Id, employee.Name}

                            This way you don't have to create a new class containing only Id and Name, but you still get the benefit of strongly-typed LINQ result, i.e. you can do

                            result.Id

                            and

                            result.Name

                            We can all discuss about benefit of var vs. declaring a variable type explicitly (i.e. var dataReader against SqlDataReader dataReader) till the cows come home and won't go anywhere. I think the benefit of var in this case is very small (if any), and if people don't want to use var for this I'm fine about it.

                            "A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin Edbert Sydney, Australia

                            T Offline
                            T Offline
                            Tom Chantler
                            wrote on last edited by
                            #36

                            This is a good answer.

                            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

                              F Offline
                              F Offline
                              Fabio Franco
                              wrote on last edited by
                              #37

                              Nishant Sivakumar wrote:

                              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

                              Yeah, for that in .net 4, the dynamic keyworkd was introduced. And I have a bad feeling about it, I think this will give me a lot of headache in the future, specially when the "give me more codezzzz plzzzzz" learn about 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."

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

                                I found the best book is "Linq in Action" - see here: Click[^]. You can then download LinqPad[^] and all the examples from the book are already loaded. Fast track to learning Linq imo.

                                It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

                                OriginalGriffO 1 Reply Last reply
                                0
                                • N Nish Nishant

                                  OriginalGriff wrote:

                                  Technically the use of "var" in the first example makes it an anonymous type, albeit a simplistic one.

                                  Well in this case the var is just an implicitly typed shortcut and the type is known at compile time. I would not call this an anonymous type at all. But I get what you mean.

                                  Regards, Nish


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

                                  S Offline
                                  S Offline
                                  Sterling Camden independent consultant
                                  wrote on last edited by
                                  #39

                                  That's just a question of how long it remains anonymous ;)

                                  Contains coding, but not narcotic.

                                  1 Reply Last reply
                                  0
                                  • L Lost User

                                    I found the best book is "Linq in Action" - see here: Click[^]. You can then download LinqPad[^] and all the examples from the book are already loaded. Fast track to learning Linq imo.

                                    It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca

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

                                    Thanks - I'll have a look. LinqPad (at a brief glance) looks like it may be worth downloading anyway.

                                    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
                                    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