473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Object instantiations

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?
Nov 19 '05 #1
2 842
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/
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
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?

Nov 19 '05 #2
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 news:%2****************@TK2MSFTNGP14.phx.gbl...
| 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/
|
|
| "Diffident" <Di*******@discussions.microsoft.com> wrote in message
| news:39**********************************@microsof t.com...
| > 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?
| >
| >
|
|
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object.cs in rotor. What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What I don't...
4
by: MA | last post by:
Hello, I've a question that I really don't know how to do a search for on the internet. The project I'm working on now is one of my first C++-projects, earlier I've been using C and Java (and VB...
7
by: Dave L | last post by:
I am inquiring about the feasability of being able to determine when an object of a certain type is instantiated. I have a base type that I want to be able to determine when each instance is...
8
by: ishekara | last post by:
Hi all, An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte member variable then also the size of the object...
0
by: Bijay Kumar | last post by:
Hi Guys, I was going through the source code of Object class (Object.cs in rotor). What I found is Equals() implemented as follows: public extern virtual bool Equals(Object obj); What...
2
by: Bob Day | last post by:
Using VS 2003, Vb, MSDE... Option 1 ------------------------------------------- Thread A and B are instantiations of 2 different classes. If thread A raises an event caught by thread B, the...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
7
by: John A Grandy | last post by:
I'm trying to get a decent idea of the relative performance of three types of implementations of data-access classes in ASP.NET 2.0. I believe this boils down to a more basic question regarding...
6
by: Osiris | last post by:
Is the following intuitively feasible in Python: I have an array (I come from C) of identical objects, called sections. These sections have some feature, say a length, measured in mm, which is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.