Generally:
To declare means to inform the compiler that something exists, so space can be allocated for it. This is separate from defining or initializing something in that it does not necessarily say what the βvalueβ of a thing is, only that it exists. In C / C ++, there is a strong difference between declaration and definition. There is a much smaller difference in C #, although the terms can still be used in a similar way.
Instantiate literally means create an instance. In programming, this usually means creating an instance of the object (usually on the heap). This is done using the new keyword in most languages. i.e.: new object(); . Most of the time you will also save the link to the object. i.e.: object myObject = new object(); .
Initializing means giving an initial value. In some languages, if you do not initialize a variable, it will contain arbitrary (dirty / garbage) data. In C #, this is actually a compile-time error for reading from an uninitialized variable.
The purpose is simply to save one value of a variable. x = 5 assigns the value 5 variable x . In some languages, an assignment cannot be combined with a declaration, but in C # it can be: int x = 5; .
Note that the operator object myObject = new object(); combines all four of them.
new object() creates a new object object , returning a reference to it.object myObject declares a new object link.= initializes the reference variable, assigning it the value of the link.
Dave Cousineau Aug 29 '15 at 22:07 2015-08-29 22:07
source share