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

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
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know