DataTypes in C#
Data Types:
Data types in C# are used to store data
into memory.
Data can be in any form like numbers,
characters, decimal and Boolean etc.
Data types in C# are mainly divided
into two parts-:
i)
Value Data Types.
ii)
Reference Data Types.
i.
Value Data Types:
Value Data Types will directly store the variable
value in memory.
We
will discuss some value data types in details as follows:
Alias
|
Type
Name |
Range |
sbyte |
System.Sbyte |
|
short |
System.Int16 |
-32768 to 32767 |
Int |
System.Int32 |
-2,147,483,648 to 2,147,483,647 |
long |
System.Int64 |
-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807 |
byte |
System.byte |
0 to 255 |
float |
System.Single |
float can hold up to 7 decimal digits. |
double |
System.Double |
double can hold up to 15 decimal digits. |
decimal |
System.Decimal |
decimal can hold up to 28 decimal digits. |
bool |
System.Boolean |
True/False |
ii.
Reference Data Types:
àThe Reference Data Types
will contain a memory address of variable value because the reference types
won’t store the variable value directly in memory.
àThe built-in reference
types are string, object.
String: It represents a sequence
of characters and its type name is System.String. So, string and String are
equivalent.
Example:
string s1 = "Tech"; //
creating through string keyword
String s2 = "Developers";
// creating through String class
Object: The object types is the base class for
all the data types in C# and can be assigned values of any other types, value
types, reference types, predefined or user-defined types.
Example:
object
id= 1;
object
name = "Tech";
object
exp=2.5
Comments
Post a Comment