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.

Variables

Declaring a variable.

int x;

Let’s define and assign a value.

x = 10;

Arrays

Declaring an array.

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

Let’s assign a value.

n[0] = 100;
n[1] = 200
raja
Published on 16-Aug-2018 09:38:32
Advertisements