Well its a silly doubt but here it goes
In a class we have members after creating object of class the members (variables etc) gets initialized i.e constructor :)
Is the values of value type goes with ZERO etc like that before obj creation ??? am i right after object creation what happens ?? constructor make then initialize to what ??
TY

VulpesPosted May 20, 2013, 5:47 AM
1. It is used in conjunction with the 'new' keyword to trigger the allocation of memory on the heap for an object of its class.
2. It calls the base class constructor.
3. It may chain to other instance constructors.
The first action is always implicit (there's no actual code visible) but the second action may be implicit (if it's a parameterless base class constructor) or explicit (using the 'base' keyword).
The third action, where present, is always explicit (using the 'this' keyword).
Secondly, instance field initialization (when dealt with in the body of the constructor) may be more complicated than just assigning a simple value, particularly when you have fields which are collections or complex objects such as controls.
A good example of the latter is a windows forms application where the form's constructor (by calling the InitializeComponent method) constructs the individual controls added to the form by the VS designer, sets their properties and 'wires up' their events to the appropriate handler.
SUNIL GUTTAPosted May 20, 2013, 11:25 PM
Hey to be frank actually i intensionally created this constructor query inorder to catch ur attension for my stop watch query as you always been active in c# language queries section but not many other in other sections .. I don't have a PM option so i don't know what to do every-time i get a problem ur my go to man ..
SUNIL GUTTAPosted May 19, 2013, 9:42 AM
Hey can you plz look the link and answer it if u can .. i hope u can
http://www.c-sharpcorner.com/Forums/Thread/210275/
VulpesPosted May 19, 2013, 9:29 AM
If they've not been assigned an actual value, then their default value corresponds to all their bytes being set to zero.
In the case of value types, this means in particular that:
1. All numbers (int, long, double etc) have a default value of 0.
2. Bools have a default value of false.
3. Chars have a default value of '\0'.
4. All enums have a default value corresponding to 0 (normally, the first member of the enum).
In the case of reference types (including string and object), the default value is null.
If they have been assigned an actual value where they're declared, then that is, of course, their initial value.
For example:
class Myclass
{
int i; // initial value 0
bool b; // initial value false
string s; // initial value null
double d = 3.0; // initial value 3
}