C# Data Types-
There are two types of data type in C#.1. Primitive (Predefine)
2. Non-Primitive (User Defined)
Primitive data types
byte
short
int
float
double
long
char
bool
datetime
string
object
Non-primitive data types
class
struct
enum
interface
delegate
array
Integer Type:
C# supports eight predefined integer types:
Name CTS Type Description Range sbyte System.SByte 8-bit signed integer -128 to 127 (-27 to 27-1)
short System.Int16 16-bit signed integer -32768 to 32767 (-215 to 215-1)
int System.Int32 32-bit signed integer -2147483648 to
2147483647 (-231 to 231-1)
long System.Int64 64-bit signed integer -9223372036854775808 to
9223372036854775807 (-263 to 263-1)
byte System.Byte 8-bit unsigned integer 0 to 255 (0 to 28-1)
ushort System.UInt16 16-bit unsigned integer 0 to 65535 (0 to 216-1)
uint System.UInt32 32-bit unsigned integer 0 to 4294967295 (0 to 232-1)
ulong System.UInt64 64-bit unsigned integer 0 to 18446744073709551615 (0 to 264-1)
Floating Point Type
Name CTS Type Description
float System.Single 32-bit single precision floating point
float System.Single 32-bit single precision floating point
double System.Double 32-bit single precision floating point
Decimal Type
Name CTS Type Description
decimal System.Decimal 128-bit high precision decimal notation
Boolean type
Name CTS Type Value
bool System.Boolean true and false
Character Type
Name CTS Type Value
char System.Char Represents a single 16-bit (Unicode character)
C# supports two predefined Reference Type
Name CTS Type Value
object System.Object The root type, from which all other types in the CTS derive (including value type)
string System.String Unicode character string
In .NET Microsoft has divided data types in two parts:
1. Value Type (Fixed in size)
2. Reference Type (Not fixed in size)
In application context, value types are stored in stack but reference types are stored in managed heap.
Value Type:
Value types are fixed in size.
Value types are made in system stack.
Actual values of data are stored in stack.
If you assign a value of a variable to another it will create two copies.
Value types are made in system stack.
Actual values of data are stored in stack.
If you assign a value of a variable to another it will create two copies.
Reference Type
Reference types are not fixed in size.
They are maintained in system managed heap but it also uses stack to store reference of heap.
Two primitive types (string and object) and non-primitive data types (class, interface & delegate) are examples of reference type.
CLR manages heap (large memory area). Heap address is accessed from stack. In reference type reference is used for processing using both managed heap and stack (operational entity).
They are maintained in system managed heap but it also uses stack to store reference of heap.
Two primitive types (string and object) and non-primitive data types (class, interface & delegate) are examples of reference type.
CLR manages heap (large memory area). Heap address is accessed from stack. In reference type reference is used for processing using both managed heap and stack (operational entity).
C# type conversions
Conversion is the process of changing the value of one Type to another. System.Convert class provides a complete set of methods for supported conversions.
There are two types of conversions:
1. Implicit Conversion
2. Explicit Conversion
Implicit Conversion
implicit conversion autometically done by the compiler .
Explicit Conversion
In Explicit conversion programmer ask the compiler to convert the value into another data type means we can do explicit conversion forcefully.
Ex:
int a = 5;
object obj = a; // Implicit Conversion
int j;
j =(int)obj; // Explicit Conversion
0 comments:
Post a Comment