Re: Default value of basic variable type
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 15 Aug 2007 16:50:37 -0700
Macneed wrote:
i am a newbie,
i remember i read a book talking about when u declare a array variable using
float[] ABC = new float[10];
the whole array element in ABC ( ABC[0] to ABC[9] ) will automatic initialize to 0
and all type of numeric variable is initialize to 0, bool type is false,
is it true?
In an instance of a class, yes. So all the floats in a "new float[10]" get initialized to the default value for the float (0). Likewise, all the bools in a "new bool[10]" get initialized to false.
Note, however, that a stack variable is not initialized. You're required to initialize it explicitly before you use it. The compiler generates an error if you attempt to use the variable before you initialize it (and in many cases, even if you do, if you're not clear enough to suit the compiler :) ).
Pete
.
- References:
- Default value of basic variable type
- From: Macneed
- Default value of basic variable type
- Prev by Date: C# Example to test Session Timeout
- Next by Date: Re: A scrolling text display that does't flash - possible in C#?
- Previous by thread: Default value of basic variable type
- Next by thread: Re: Default value of basic variable type
- Index(es):
Relevant Pages
|