Home >Backend Development >C#.Net Tutorial >What is the difference between declaration and definition in C#?

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

王林
王林forward
2023-08-26 08:37:02827browse

C# 中的声明和定义有什么区别?

Declaration means only declaring the variable and allocating memory, but not setting any value.

But definition means that the variable has been initialized.

The same is true for variables, arrays, collections, etc.

Variables

Declare variables.

int x;

Let's define and assign a value.

x = 10;

Array

Declare an array.

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

Let's assign a value.

n[0] = 100;
n[1] = 200

The above is the detailed content of What is the difference between declaration and definition in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Final keyword in C#Next article:Final keyword in C#