What is the difference between declaration and definition in C#?

CsharpProgrammingServer Side Programming

Declaration means that variable is only declared and memory is allocated, but no value is set.

However, definition means the variables has been initialized.

The same works for variables, arrays, collections, etc.


Declaring a variable.

int x;

Let’s define and assign a value.

x = 10;


Declaring an array.

int [] n // declaring
int n= new int[10]; // initializing

Let’s assign a value.

n[0] = 100;
n[1] = 200
Published on 16-Aug-2018 13:08:32