Object instantiations

G

Guest

Hello All,

Can someone please answer my question on how the following objects would be
instantiated?

- - - - - - - - - - - -

public class CustomPaging
{
private int _PageSize = 10; // Default page size
secure.WebServices.General objGeneral = new secure.WebServices.General();
private DataSet _DataSet = new DataSet();
private DataTable _DataTable = new DataTable();

public CustomPaging()
{
//
// TODO: Add constructor logic here
//

}

........

method1()
{ }

method2()
{}

} // end of class


- - - - - - - - - -- - - - - - -

In the above piece of code, I am instantiating few variables and objects
just after public class CustomPaging. My question is if suppose I create an
object of this class and call method1 followed by method2....how many times
would the objects be created?

I know that had I kept the initialization code in the constructor, they
would be initialized only once, i.e., when the object is created. But how
about in this case where they are not initialized in the constructor?
 
K

Karl Seguin

Only once. I want to say it's the same as initializing them in the
constructor (and you won't see any differences, it'l behave the same) but
there are probably design differences or very technical differences I'm not
aware of...

Karl
 
B

bruce barker

the main difference is they are created before the class constructor is
called.

-- bruce (sqlwork.com)



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message | Only once. I want to say it's the same as initializing them in the
| constructor (and you won't see any differences, it'l behave the same) but
| there are probably design differences or very technical differences I'm
not
| aware of...
|
| Karl
|
| --
| MY ASP.Net tutorials
| http://www.openmymind.net/
|
|
| | > Hello All,
| >
| > Can someone please answer my question on how the following objects would
| be
| > instantiated?
| >
| > - - - - - - - - - - - -
| >
| > public class CustomPaging
| > {
| > private int _PageSize = 10; // Default page size
| > secure.WebServices.General objGeneral = new
| secure.WebServices.General();
| > private DataSet _DataSet = new DataSet();
| > private DataTable _DataTable = new DataTable();
| >
| > public CustomPaging()
| > {
| > //
| > // TODO: Add constructor logic here
| > //
| >
| > }
| >
| > ........
| >
| > method1()
| > { }
| >
| > method2()
| > {}
| >
| > } // end of class
| >
| >
| > - - - - - - - - - -- - - - - - -
| >
| > In the above piece of code, I am instantiating few variables and objects
| > just after public class CustomPaging. My question is if suppose I create
| an
| > object of this class and call method1 followed by method2....how many
| times
| > would the objects be created?
| >
| > I know that had I kept the initialization code in the constructor, they
| > would be initialized only once, i.e., when the object is created. But
how
| > about in this case where they are not initialized in the constructor?
| >
| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top