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. Other Discussions
  3. The Weird and The Wonderful
  4. When professionals don't think

When professionals don't think

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpcsslinqtutorialquestion
11 Posts 9 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.
  • OriginalGriffO OriginalGriff

    This is taken directly from a book on LINQ, and illustrates how you could use a IEnumerable<int> to generate a never ending sequence:

        public static IEnumerable<int> GetList()
            {
            int i = 2;
            while (true)
                {
                i = i \* 2;
                if ((i <= 0) || (i > int.MaxValue))
                    {
                    i = 2;
                    Console.WriteLine("Enter to continue, CTRL-C to break.");
                    Console.ReadLine();
                    }
                else
                    {
                    yield return i;
                    }
                }
            }
    

    For your homework, please list all the values for which "i > int.MaxValue" :laugh: Now, aren't we all glad he checked for less than zero as well?

    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
    Luc Pattyn
    wrote on last edited by
    #2

    A classic. Works really well with unsigned int, no negatives to the rescue. :)

    Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

    1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      This is taken directly from a book on LINQ, and illustrates how you could use a IEnumerable<int> to generate a never ending sequence:

          public static IEnumerable<int> GetList()
              {
              int i = 2;
              while (true)
                  {
                  i = i \* 2;
                  if ((i <= 0) || (i > int.MaxValue))
                      {
                      i = 2;
                      Console.WriteLine("Enter to continue, CTRL-C to break.");
                      Console.ReadLine();
                      }
                  else
                      {
                      yield return i;
                      }
                  }
              }
      

      For your homework, please list all the values for which "i > int.MaxValue" :laugh: Now, aren't we all glad he checked for less than zero as well?

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

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #3

      Had it been some C code before? And the guy to port it did not understand what he was doing?

      C OriginalGriffO 2 Replies Last reply
      0
      • B Bernhard Hiller

        Had it been some C code before? And the guy to port it did not understand what he was doing?

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #4

        I think just the end of youur question/statement is all that is needed. :)

        Bernhard Hiller wrote:

        did not understand what he was doing?

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

        1 Reply Last reply
        0
        • B Bernhard Hiller

          Had it been some C code before? And the guy to port it did not understand what he was doing?

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

          Unfortunately not: the whole book is LINQ, which is not available in C (nor are IEnumerable interfaces). And I think they should know what they are doing: the two authors are "Community Program Manager for the Microsoft C# Team" and "Senior Program Manager in the Microsoft .NET Developer Platform Team" according to "about the Author". Now I think about it, it explains a lot about MS software, really... :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

          M 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            This is taken directly from a book on LINQ, and illustrates how you could use a IEnumerable<int> to generate a never ending sequence:

                public static IEnumerable<int> GetList()
                    {
                    int i = 2;
                    while (true)
                        {
                        i = i \* 2;
                        if ((i <= 0) || (i > int.MaxValue))
                            {
                            i = 2;
                            Console.WriteLine("Enter to continue, CTRL-C to break.");
                            Console.ReadLine();
                            }
                        else
                            {
                            yield return i;
                            }
                        }
                    }
            

            For your homework, please list all the values for which "i > int.MaxValue" :laugh: Now, aren't we all glad he checked for less than zero as well?

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

            R Offline
            R Offline
            Ravi Sant
            wrote on last edited by
            #6

            Classic pick. The guys at Microsoft must get back to clear basics.

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              This is taken directly from a book on LINQ, and illustrates how you could use a IEnumerable<int> to generate a never ending sequence:

                  public static IEnumerable<int> GetList()
                      {
                      int i = 2;
                      while (true)
                          {
                          i = i \* 2;
                          if ((i <= 0) || (i > int.MaxValue))
                              {
                              i = 2;
                              Console.WriteLine("Enter to continue, CTRL-C to break.");
                              Console.ReadLine();
                              }
                          else
                              {
                              yield return i;
                              }
                          }
                      }
              

              For your homework, please list all the values for which "i > int.MaxValue" :laugh: Now, aren't we all glad he checked for less than zero as well?

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

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #7

              What book?

              -- Kein Mitleid Für Die Mehrheit

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                This is taken directly from a book on LINQ, and illustrates how you could use a IEnumerable<int> to generate a never ending sequence:

                    public static IEnumerable<int> GetList()
                        {
                        int i = 2;
                        while (true)
                            {
                            i = i \* 2;
                            if ((i <= 0) || (i > int.MaxValue))
                                {
                                i = 2;
                                Console.WriteLine("Enter to continue, CTRL-C to break.");
                                Console.ReadLine();
                                }
                            else
                                {
                                yield return i;
                                }
                            }
                        }
                

                For your homework, please list all the values for which "i > int.MaxValue" :laugh: Now, aren't we all glad he checked for less than zero as well?

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

                K Offline
                K Offline
                Keith Barrow
                wrote on last edited by
                #8

                The books not by Dietel & Dietel by any chance? They seem to have written exactly one book (in c++ I suspect) then re-written if for a variety of OO languages. The VB.net X| book has Get_Value_() Set_Value_() methods over properties. We're currently using this as the course text X| :~ X|

                Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                -Or-
                A Dead ringer for Kate Winslett[^]

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  This is taken directly from a book on LINQ, and illustrates how you could use a IEnumerable<int> to generate a never ending sequence:

                      public static IEnumerable<int> GetList()
                          {
                          int i = 2;
                          while (true)
                              {
                              i = i \* 2;
                              if ((i <= 0) || (i > int.MaxValue))
                                  {
                                  i = 2;
                                  Console.WriteLine("Enter to continue, CTRL-C to break.");
                                  Console.ReadLine();
                                  }
                              else
                                  {
                                  yield return i;
                                  }
                              }
                          }
                  

                  For your homework, please list all the values for which "i > int.MaxValue" :laugh: Now, aren't we all glad he checked for less than zero as well?

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

                  _ Offline
                  _ Offline
                  _Erik_
                  wrote on last edited by
                  #9

                  Now I understand why we find some of the questions we can see in the forums...

                  OriginalGriffO 1 Reply Last reply
                  0
                  • _ _Erik_

                    Now I understand why we find some of the questions we can see in the forums...

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

                    :laugh: I hadn't thought of that!

                    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
                    • OriginalGriffO OriginalGriff

                      Unfortunately not: the whole book is LINQ, which is not available in C (nor are IEnumerable interfaces). And I think they should know what they are doing: the two authors are "Community Program Manager for the Microsoft C# Team" and "Senior Program Manager in the Microsoft .NET Developer Platform Team" according to "about the Author". Now I think about it, it explains a lot about MS software, really... :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."

                      M Offline
                      M Offline
                      Momony
                      wrote on last edited by
                      #11

                      You had me at the word "Manager". Explains it all. I am half a manager now, and my code has been deteriorating at an alarming rate.

                      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