Jump to content


Photo

No Dumb Questions In Chapter 3, About Joe And Bob


  • Please log in to reply
2 replies to this topic

#1 jmcnelis

jmcnelis

    New Member

  • Members
  • Pip
  • 5 posts

Posted 03 February 2014 - 10:20 PM

I have a question that looks like it may have gone in this section. It's the part talking about "Guy bob = new Guy()". I understand why the method Form1() doesn't have "Guy bob = new Guy()" in it, why it's only "bob = new Guy()" but the question I have is, why not at the top of the class, where you have "Guy bob" setting bob as a variable of type Guy do you not have "Guy bob = new Guy()"? Wouldn't that do the same thing, setting up bob as a new Guy() right off the bat, instead of putting it in the Form1() method? You do it for bank, setting it as an int variable and assigning 100 to it, I don't see why it can't be done with the bob variable also.

#2 AndrewStellman

AndrewStellman

    Andrew Stellman

  • O'Reilly Author
  • PipPipPipPipPipPipPipPipPipPipPip
  • 821 posts
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 05 February 2014 - 05:46 PM

If I understand you correctly -- yes, that would work, those would do the same thing. There are many different ways to write code that does the same thing. :) I chose that particular way because after a lot of trial and error, it seemed to be the most obvious to the most new learners.

Anyway, from what you wrote, it sounds like you understand what's going on.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com

#3 jmcnelis

jmcnelis

    New Member

  • Members
  • Pip
  • 5 posts

Posted 05 February 2014 - 08:47 PM

Thanks for the reply! I did try it out and it worked, I was just curious as to the reasoning behind it. :) Actually, as I'm looking through some of the coding examples, I like the way it's laid out like that, with the variables set at the top, and then being assigned variables later on.

And yeah, I kinda know what's going on, I studied COBOL years ago and was pretty good at it, and I do some scripting in a java-like language for a game I play, so I have some background in coding. Now trying to learn something I can put to practical use!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users