Variables


Variables

A variable is nothing more than a name that our programs can change for a storage place. Each variable in C# has a specific type that determines the memory size and layout of the variable by the range and the number of operations to be applied to that variable that can be saved inside that memory.

The fundamental values in C# can be classified as −

Type Example
Integral types byte, sbyte, ushort, short, uint, int, ulong, long, and char
Floating point types double and float
Decimal types decimal
Boolean types true / false values, as assigned
Nullable types Nullable types

C# also allows you to define other variable value types such as enum and variables references such as a class included in the next chapters.

Defining Variables

The C# variable default syntax is –

< data_type > < variable_list >;

In this case, the data type must include a valid C# data type, including the char, the int, the float, and the double or any user-defined data type.

Initializing Variables

Variables containing an equal signal followed by a constant expression are initialized (attributed value). The main way to initialize is —

variable_name = value;

In their declaration, variables may be initialised. The initializer is a symbol that is equal to a constant phrase as –

< data_type > < variable_name > = value;

Lvalue and Rvalue Expressions in C#

C# contains two types of terms −

  • lvalue − A lvalue expression may occur on the left or the right side of the assignment.
  • Rvalue – A value expression on the left but on the right side of the assignment may appear.

Variables are values and can be found on the left of a task. Numeric literals are value values and cannot be allocated on the left.
Programs can change for a storage place. Each variable in C# has a specific type that determines the memory size and layout of the variable by the range and the number of operations to be applied to that variable that can be saved inside that memory.