M
MBALOVER
Hi all,
I am a new bee in OOP. In C#, assume I have two version of the class
Form1
Version 1:
public class Form1: Form
{
Button mybutton= new Button();
public void Form1
{
this.mybutton.Text="aaaa";
this.Controls.Add(mybutton);
}
}
And Version 2:
public class Form1: Form
{
Button mybutton;
public void Form1
{
this.mybutton=new Button();
this.mybutton.Text="aaaa";
this.Controls.Add(mybutton);
}
}
The difference between the two versions is the declaration of the
object mybutton. In Version 1, the mybutton is assigned a memory
outside the constructor function while in Version 2 it is assigned a
memory inside. (here, with assigning a memory location, I mean the
command new).
So can you please tell me if the two versions perform exactly the
same, or there is some difference that I should note about?
Thanks
I am a new bee in OOP. In C#, assume I have two version of the class
Form1
Version 1:
public class Form1: Form
{
Button mybutton= new Button();
public void Form1
{
this.mybutton.Text="aaaa";
this.Controls.Add(mybutton);
}
}
And Version 2:
public class Form1: Form
{
Button mybutton;
public void Form1
{
this.mybutton=new Button();
this.mybutton.Text="aaaa";
this.Controls.Add(mybutton);
}
}
The difference between the two versions is the declaration of the
object mybutton. In Version 1, the mybutton is assigned a memory
outside the constructor function while in Version 2 it is assigned a
memory inside. (here, with assigning a memory location, I mean the
command new).
So can you please tell me if the two versions perform exactly the
same, or there is some difference that I should note about?
Thanks