473,386 Members | 1,720 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,386 software developers and data experts.

Help with the magically instantiating collection class

Hi everyone,

I posted a question earlier about a collection class that I'd made seemingly
getting instantiated magically after a class that contained a variable of
that type had its constructor called.

The constructor didnt touch the collection class and defineately didn't
initialise it.

Some one suggested the following reason as what is happening.

If anyone can help with what I've said down below i'd be very greatful:

Thanks

Field initialization
The initial value of a field, whether it be a static field or an instance
field, is the default value (§5.2) of the field's type. It is not possible
to observe the value of a field before this default initialization has
occurred, and a field is thus never "uninitialized".


I'm not really sure what to make of that. How come, if I dont initialise, by
means of a constructor, a string for example - its null until I give it
something?

Thanks
Nov 16 '05 #1
2 1053
Not sure the exact point that troubles you.

Keep in mind that .NET applications are under the control of a runtime. This
runtime takes care of "initializing" variables instead of letting whatever
was in memory before...

I don't really see though how it's relate to the "automagically instantiated
collection". If you mean the variable is null, the collection is not
instanciated. Tehcnically you just have a pointer to your collection that
currently points to nothing. It will be instantiated actually when you "new"
the variable.

Technically :
- space is reserved for variables
- this space is filled with 0

Objects are under the hood pointers ie. the variable for objects will be
null (ie. pointing to nowhere) and you'll have to "new" the variavble to
really allocate an object.

Patrice


--

"thechaosengine" <sh856531@microsofts_free_email_service.com> a écrit dans
le message de news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi everyone,

I posted a question earlier about a collection class that I'd made seemingly getting instantiated magically after a class that contained a variable of
that type had its constructor called.

The constructor didnt touch the collection class and defineately didn't
initialise it.

Some one suggested the following reason as what is happening.

If anyone can help with what I've said down below i'd be very greatful:

Thanks

Field initialization
The initial value of a field, whether it be a static field or an instance field, is the default value (§5.2) of the field's type. It is not possible to observe the value of a field before this default initialization has
occurred, and a field is thus never "uninitialized".
I'm not really sure what to make of that. How come, if I dont initialise,

by means of a constructor, a string for example - its null until I give it
something?

Thanks

Nov 16 '05 #2
"thechaosengine" <sh856531@microsofts_free_email_service.com> wrote:
The initial value of a field, whether it be a static field or an
instance
field, is the default value (§5.2) of the field's type. It is not
possible
to observe the value of a field before this default initialization
has
occurred, and a field is thus never "uninitialized".


I'm not really sure what to make of that. How come, if I dont
initialise,
by means of a constructor, a string for example - its null until I
give it
something?


String is a reference type, and the "default value" for any reference
type is null. As the spec says, "the initial value of a field ... is
the default value of the field's type"- i.e. a string that has not
been explicitly initialised will be null.

P.
Nov 16 '05 #3

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

Similar topics

1
by: Matthew Hood | last post by:
Here's the situation. I am developing an ASP.NET web application. Most of my forms will be accessing a database (MS Access) for either record creation/deletion/updating or for list lookups. The...
1
by: thechaosengine | last post by:
Hi everyone, I posted a question earlier about a collection class that I'd made seemingly getting instantiated magically after a class that contained a variable of that type had its constructor...
2
by: Cider123 | last post by:
Trying to figure out how to replicate the same interface as what a ListView control has. I have everything working for the most part, with exception of 1 minor setback. I can't seem to pass...
1
by: MrNobody | last post by:
What I was hoping to do was have a universal Windows Form which features a DataGrid. This Formcould be accessed from several different points of entry, each one may require a different style...
2
by: FredC | last post by:
S Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1...
9
by: Carl | last post by:
Hi, I have a class in .Net which I instantiate in my code behind on one of my aspx pages. When I am finished with the instance, what is teh best method of taking it out of memory. Should I...
2
by: HarishP | last post by:
Hi, How to avoid instantiating the class more than 10 times Harish.P Sr. Software Engineer Comat Technologies Pvt. Ltd., Bangalore Email: harish.p@comat.com
2
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require...
3
by: Nagesh | last post by:
hi, I have seen the winvnc(tightvnc server) source code in this I seen that class member funtions are calling without instantiating the object i.e. like vncService::ShowDefaultProperties() where...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.