Introduction
A valid C# variable's data type specifies the type of data it can carry. Because each type of data (such as integer, character, float, and so on) is predefined as part of the programming language, all constants and variables defined for a given program must be described using one of the data types.
C# data types are grouped into three groups.
- Value types
- Reference types
- Pointer types
Value Type
Value type variables can be assigned a value. They are derived from the System class. ValueType. Data is directly contained in the value types. Int, char, and float are three examples of data types that hold numbers, alphabets, and floating-point numbers, respectively. The System allocates RAM to store the value when declaring an int type. The following are the many Value Data Types available in the C# programming language:
Signed and Unsigned Integral Types:
Eight integral types support signed and unsigned 8-bit, 16-bit, 32-bit, and 64-bit numbers.
Floating Point Types:
The decimal point is included in two floating-point data formats.
Float is a 32-bit floating-point type with single precision. Precision is seven digits. Use the suffix for F to initialize a float variable. For example, float x = 3.5F; It is viewed as double if the suffix F or f is not used.
Double is a double-precision 64-bit floating-point type. It has a precision of 14 to 15 digits. Use the suffix d or D to initialize a double variable. However, suffixes are not required because floating data types are always of the double type.
Decimal Types:
The decimal data type is a 128-bit data type that can be used to do financial and monetary calculations. Precision is 28-29 digits. Use the suffix m or M to initialize a decimal variable. Decimal x = 300.5m; is an example. It is viewed as double if the suffix m or M is not used.
Character Types:
The character types represent a UTF-16 code unit or a 16-bit Unicode character.
Boolean Types:
Either true or false must be assigned to it. Values of type bool are not transformed to any other type, either implicitly or explicitly (through casts). The programmer, on the other hand, can easily write conversion code.