Technically what are the meanings and differences of the terms declaring, instantiating, initializing and assigning an object in C#?
I think I know the meaning of assigning but I have no formal definition.
In msdn, it is said "the act of creating an object is called instantiation". But the meaning creating seems vague to me. You can write
int a; is a then created?
In computer programming, initialization (or initialisation) is the assignment of an initial value for a data object or variable. The manner in which initialization is performed depends on the programming language, as well as the type, storage class, etc., of an object to be initialized.
Initialization-Assigning a value to a variable i.e a=0,setting the initial values. Instantiation- Creating the object i.e when u r referencing a variable to an object with new operator.
Instantiate in Java means to call a constructor of a Class which creates an an instance or object, of the type of that Class. Instantiation allocates the initial memory for the object and returns a reference.
Instantiate (a verb) and instantiation (the noun) in computer science refer to the creation of an object (or an “instance” of a given class) in an object-oriented programming (OOP) language. Referencing a class declaration, an instantiated object is named and created, in memory or on disk.
Declaring - Declaring a variable means to introduce a new variable to the program. You define its type and its name.
int a; //a is declared Instantiate - Instantiating a class means to create a new instance of the class. Source.
MyObject x = new MyObject(); //we are making a new instance of the class MyObject Initialize - To initialize a variable means to assign it an initial value.
int a; //a is declared int a = 0; //a is declared AND initialized to 0 MyObject x = new MyObject(); //x is declared and initialized with an instance of MyObject Assigning - Assigning to a variable means to provide the variable with a value.
int a = 0; //we are assigning to a; yes, initializing a variable means you assign it a value, so they do overlap! a = 1; //we are assigning to a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With