Choosing the correct data type for a variable is crucial as it specifies the size and type of values that it can hold. Using the wrong data type can result in errors, and waste time and memory.
In the C# programming language,there are three types of data:
Value Data Type (int, float, char, bool, etc)
Reference Data Type (class, object, string, and interface)
Pointer Data Type (pointer)
It is crucial to choose the appropriate data type for each variable to enhance the readability and maintainability of your code. The most commonly used data types are:
Integer Types
int:
It can store integers such as positive numbers like 143 or negative numbers like -153.
Range: -2,147,483,648 to 2,147,483,647.
Example
intmyNumber=20000;
Console.WriteLine(myNumber);
long:
Handles larger whole numbers.
Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.