C# DATA TYPES :
As explained in the variables chapter , "A variables in C# must be a specified data type " .
EXAMPLE :
int myNum = 5; // Integer (whole number)
double myDoubleNum = 5.99D; // Floating point number
char myLetter = 'D'; // Character
bool myBool = true; // Boolean
string myText = "Hello"; // String
TRY IT YOURSELF :
ADVANTAGES OF DATA TYPE :
A Data type specifies the size and type of variable value . It is important to use the correct data type for the Corresponding Variable ; to avoid errors , to save time and memory .
The most common types are :
NUMBERS :
Numbers types are divided into two groups :
* INTEGER TYPE
* FLOTING POINT TYPE
INTEGER TYPE :
Stores whole number , positive or negative (such as 123 or - 123),without decimals valid types are int and long . which type you should use ,depends on the numeric value .
FLOATING TYPE :
Represents numbers with a fractional parts containing one or more decimals valid types are float and double.
NOTE :
Even though there are many numeric types in C# the most used for numbers are int (for whole numbers ) and double (for floating point numbers ).
INTEGER TYPE :
* INT : -
The int data type can store whole number from -21345678 to 21345678 . The int data type is the preferred data type when we create variables with a numeric value .
TRY IT YOURSELF :
*LONG ;-
The long data type can store whole numbers from -1234567890876 to 123456789976.This is used when int is not large enough to store the value . Note that you should end the value with an "L".
TRY IT YOURSELF :
You should use a floating point type whenever you need a number with a decimal ,such as 9.99 or 3.13453
* FLOAT ;-
The float data type can store fractional numbers from 3.4 e - 038 to 3.4 e +038 .Note that you should end the value with an "F".
TRY IT YOURSELF :
DOUBLE : -
The double data type can store fractional numbers from 1.7e - 308 to 1.7e + 308 . Note that you should end the value with an "D".
TRY IT YOURSELF :