John  Burns

John Burns

  • NA
  • 120
  • 109.2k

splitting up an Initializer

Jan 4 2011 2:19 AM

hey again guys and thanks for all your support in the past questions.
 
this is just a question of prefference really and what way is best.
 
i made a simple class as i was working through my study book, a class called Guy
i then came into the main form 1and then i made instances outside the form but inside the class so they can be accessed from any method in that form, the thing is though the initializers were split,
 
so rather than having my usual:
Guy john = New John();
 
 i had it split in 2 parts like this:
 
public partial class Form1 : form
{
Guy john;
public Form1()
   {
         InitializeComponent();
john = new Guy ();
   }
}
 
 
whay would they do this? the the book doesnt say so i tried to figure it out myself and came accross a discovery; the program will just fine i move the code about and join it back together like this:
public partial class Form1 : form
{
Guy john = new John();
public Form1()
   {
         InitializeComponent();
   }
}
 
 
so the conculusion i came to is that it does not matter if the code is placed in 2 parts or as one line so that it can be accessed from the form in any method; it still does the same job. am i correct?
 
thanks

Answers (7)