Sunday, October 20, 2019 14:34

Declaring and initializing variables

The next topic in our lessons will be declaring and initializing variables. What do those term mean?

As we already said in a previous lesson, declaring a variable means creating a new variable, by telling the compiler its type and its name. However, our new variable is only created. It does not contain yet any value. This is where initialization comes in.

Initializing a variable means declaring a first, default, value to it, using the assign operator of C# (the equal character – “=”). Here is an example of declaring and initializing variables:

It is also possible to merge the two terms in a single instruction:

The compiler also allows us to declare multiple variables of the same type in a single instruction:

As you could guess, the compiler also allows us to initialize variables declared in a single instruction:



Tags: , ,

Leave a Reply