O'Reilly Forums: No Dumb Questions In Chapter 3, About Joe And Bob - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

No Dumb Questions In Chapter 3, About Joe And Bob

#1 User is offline   jmcnelis 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 29-September 13

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

#2 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 803
  • Joined: 08-October 08
  • 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
0

#3 User is offline   jmcnelis 

  • New Member
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 29-September 13

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users