Integral Data Types

Identifiers and Data Types

Every variable has:

Integer Data Type

Integral data types are as follows:

Double Data Type

Floating-Point Number

Contains decimal positions and the data types are as follows:

Char Data Type

Chars can be assigned values as follows: char letterGrade; letterGrade = 'B' or char letterGrade = 'B' This can be changed later for example; letterGrade = 'A' chars are always enclosed in Single Quotes (').

Bool Data Type

bool can be assigned values as follows: bool married; married = true; Or bool married = true; and then change later for example: married = false; More details on C# data types are included here:

Arithmetic Operators

Operators in C# are shown in this table:

Operator Precedence in C# depends on order in which the operators are evaluated:

Examples: What is the value of number?

  1. int number; number = 4 + 2 * 3;
  2. int number; number = (4 + 2) * 3
Answers:
  1. number = 10
  2. number = 18

Type Conversion (Casting)

Casting means changing the variable from one data type to another. Casting an integer to a double (implicit casting). See example here:

Casting a double to an integer (explicit casting) See example:

Casting an integer to a string. See example:

Casting an string to a number (int). See example:

Casting an string to a number (double). See example:


For more details, please contact me here.
Date of last modification: 2021