Strictly in terms of C# the above are not exactly correct
// Declaration = memory allocation
int x;
For types with value-semantics the above is true, but for types with reference-semantics it is not, because there is no allocation that happens. The difference is that memory allocation happens with the new
keyword with references. With value types, they are stored in the stack, and the stack is pre-allocated to 4Mb size when a .NET process starts.
An example would be
string x;
the above statement only tells the compiler what x
is, and nothing happens really in the program when this is compiled.
// Initialization = set initial value
x = 0;
Here again, I would argue the above is just an assignment, and not necessarily an initial value as nothing stops you from writing
x = 1;
x = 2;
There is nothing different between these two assignments, making one of the an initial value and the other not. This is because we don't know if x
was assigned a value somewhere else before.
// Definition = declaration and initialization
int y = 0;
I would call it just an initialization as here fore sure a value is assigned fro the first time.
// Assignement = set a new value
y = 1;
As I said before the above is just an assignment.