Data type in C#There are two types of data type in C#:1.A built-in data type2.A user-defined data type
built-in data type are further divided as:byteshortintfloatdoublelongcharbooldatetimestringobjectetc
A user-defined data type are further divided as:classstructenuminterfacedelegatearray
Encoding Scheme To represent coding scheme.ASCII 8 bits 28 = 256ANSI 7 bits 78 = 128Unicode character sets 16 bits 216 = 65000UTF (Unicode text file) can be:UTF 7UTF 8UTF 16UTF 32
Integer TypeC# supports eight predefined integer types:NameCTS TypeDescriptionRangesbyteSystem.SByte8-bit signed integer-128 to 127 (-27 to 27-1)shortSystem.Int1616-bit signed integer-32768 to 32767 (-215 to 215-1)intSystem.Int3232-bit signed integer-2147483648 to2147483647 (-231 to 231-1)longSystem.Int6464-bit signed integer-9223372036854775808 to9223372036854775807 (-263 to 263-1)byteSystem.Byte8-bit unsigned integer0 to 255 (0 to 28-1)ushortSystem.UInt1616-bit unsigned integer0 to 65535 (0 to 216-1)uintSystem. UInt3232-bit unsigned integer0 to 4294967295 (0 to 232-1)ulongSystem. UInt6464-bit unsigned integer0 to 18446744073709551615 (0 to 264-1)
Floating Point TypeNameCTS TypeDescriptionSignificant FiguresRange (approx.)floatSystem.Single32-bit single precision floating point7plus & minus 1.5 X 10-45 to Â±3.4 X 1038doubleSystem.Double32-bit single precision floating point15/16plus & minus 5.0 X 10-3245 to Â±3.4 X 10308
Decimal TypeNameCTS TypeDescriptionSignificant FiguresRange (approx.)decimalSystem.Decimal128-bit high precision decimal notation28plus & minus 1.0 X 10-28 to Â±7.9 X 1028
Boolean TypeNameCTS TypeValuesboolSystem.Booleantrue and false
Character TypeNameCTS TypeValuescharSystem.CharRepresents a single 16-bit (Unicode) character)
C# supports two predefined Reference TypeNameCTS TypeValuesobjectSystem.ObjectThe root type, from which all other types in the CTS derive (including value type)stringSystem.StringUnicode character stringIn .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.
All primitive data type except string and object are example of value types.Object is a super type. It can store any type and any size of data. Object is called super type because it helps in inheritance.struct and enum are value type.Note: Stack is an operation entity (LIFO) i.e. it is fixed in size.
- 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.
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).
- 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.
Sunday, 17 February 2013
Data type in C#.net
Posted by Siva at Sunday, February 17, 2013