Data Types in C#
Notes:
Data Types in C# Programming Language:
Data type:
As the name itself indicating, data type means type of data.
Note: While developing any software application; we come across different types of data and data values. We need to store and process them efficiently.
Game:
playerScore= 10; // playerScore is an integer type data
worldGravity =9.8; // worldGravity is a real type data
re-play=’y’; // re-play is a character type data
Banking application:
accountNumber=10; // accountNumber is an integer type data
rateOfInterest=13.5; // rateOfInterest is a real type data
hasLoan=’y’; // hasLoan is a character type data
Types of data types:
To store and process different types of data and data values efficiently;
C# provides mainly 2 types of data types.
1. Primitive or basic or built-in
2. Non primitive or derived or composite
Primitive data types are again divided in to:
Value types:
- allow us to store and process the actual value
Reference types:
- allow us to store and process the address of another memory location
Value types are again divided in to:
Numeric types:
- allow us to store and process the numbers (i.e. integer and real numbers)
Nonnumeric types:
- allow us to store and process the non numeric values (i.e. characters and Boolean values)
Numeric types are again divided in to:
Integer types:
- allow us to store and process the integer numbers (i.e. numbers without decimal point)
Ex: 22, -44, 2017, etc.
Real types:
- allow us to store and process a real numbers (i.e. numbers containing decimal point)
Ex: 3.142, 9.8, 2.123456, 3.4E+38
Integer types are again divided in to:
sbyte, short, int and long data types: signed integer types
- allow us to store and process the +ve as well as –ve integer numbers
Ex: 22, -44, 128 etc.
byte, ushort, uint and ulong data types: unsigned integer types
- allow us to store and process only the +ve integer numbers
Ex: 22, 44, 128 etc.
Real types are again divided in to:
float, double, and decimal data types:
- allow us to store and process the real numbers containing 6-9, 15-17 or 28-29 digits after the decimal point.
Ex: 3.142, 2.71812, 3.3333333 etc.
Nonnumeric types are again divided in to:
bool data type:
- allows us to store and process the Boolean values
Ex: true or false
char data type:
- allows us to store and process a symbol enclosed in pair of single quotations
Ex: ‘A’, ‘9’, ‘$’, ‘\n’ etc.
void data type:
- indicates a value less data type
Reference types are again divided in to:
pointer:
- is used to store and process the address of another memory location
string:
- is used to store and process sequence of characters enclosed in pair of double quotations
object:
- is used to store and process any type of data value
Non-primitive types are again divided in to:
array:
- is used to store and process the list of data values
structure:
- is used to store and process a record of information
class:
- is used to store and process an object information
enum:
- is used to store and process the list of enumerated words
interfaces, events, delegates and other data structures …