Value type variables can be assigned a value directly. They are derived from the class System.ValueType.
Short Name
|
.NET Class
|
Type
|
Width
|
Range (bits)
|
byte
|
Unsigned integer
|
8
|
0 to 255
|
|
sbyte
|
Signed integer
|
8
|
-128 to 127
|
|
int
|
Signed integer
|
32
|
-2,147,483,648 to 2,147,483,647
|
|
uint
|
Unsigned integer
|
32
|
0 to 4294967295
|
|
short
|
Signed integer
|
16
|
-32,768 to 32,767
|
|
ushort
|
Unsigned integer
|
16
|
0 to 65535
|
|
long
|
Signed integer
|
64
|
-9223372036854775808 to 9223372036854775807
|
|
ulong
|
Unsigned integer
|
64
|
0 to 18446744073709551615
|
|
float
|
Single-precision floating point type
|
32
|
-3.402823e38 to 3.402823e38
|
|
double
|
Double-precision floating point type
|
64
|
-1.79769313486232e308 to 1.79769313486232e308
|
|
char
|
A single Unicode character
|
16
|
Unicode symbols used in text
|
|
bool
|
Logical Boolean type
|
8
|
True or false
|
|
object
|
Base type of all other types
|
|||
string
|
A sequence of characters
|
|||
decimal
|
Precise fractional or integral type that can
represent decimal numbers with 29 significant digits
|
128
|
±1.0 × 10e−28 to ±7.9 × 10e28
|
IMPLICIT CONVERSIONS
The following is a list of implicit conversions between .NET Framework data types:
int int1 = 5; long long1 = int1; //implicit conversion
Source Type
|
Target Type
|
Byte
|
short, ushort, int, uint, long, ulong, float,
double, or decimal
|
Sbyte
|
short, int, long, float, double, or decimal
|
Int
|
long, float, double, or decimal
|
Uint
|
long, ulong, float, double, or decimal
|
Short
|
int, long, float, double, or decimal
|
Ushort
|
int, uint, long, ulong, float, double, or decimal
|
Long
|
float, double, or decimal
|
Ulong
|
float, double, or decimal
|
Float
|
double
|
Char
|
ushort, int, uint, long, ulong, float, double, or
decimal
|
EXPLICIT CONVERSIONS
The following table lists explicit conversions:
long long2 = 5483; int int2 = (int)long2; //explicit conversion
Source Type
|
Target Type
|
Byte
|
sbyte or char
|
Sbyte
|
byte, ushort, uint, ulong, or char
|
Int
|
sbyte, byte, short, ushort, uint, ulong, or char
|
Uint
|
sbyte, byte, short, ushort, int, or char
|
Short
|
sbyte, byte, ushort, uint, ulong, or char
|
Ushort
|
sbyte, byte, short, or char
|
Long
|
sbyte, byte, short, ushort, int, uint, ulong, or
char
|
Ulong
|
sbyte, byte, short, ushort, int, uint, long, or char
|
Float
|
sbyte, byte, short, ushort, int, uint, long, ulong,
char, ordecimal
|
Double
|
sbyte, byte, short, ushort, int, uint, long, ulong,
char, float, or decimal
|
Char
|
sbyte, byte, or short
|
Decimal
|
sbyte, byte, short, ushort, int, uint, long, ulong,
char, float, or double
|
C# Type Conversion Methods
Sr.No
|
Methods & Description
|
1
|
ToBoolean
Converts a
type to a Boolean value, where possible.
|
2
|
ToByte
Converts a
type to a byte.
|
3
|
ToChar
Converts a
type to a single Unicode character, where possible.
|
4
|
ToDateTime
Converts a
type (integer or string type) to date-time structures.
|
5
|
ToDecimal
Converts a
floating point or integer type to a decimal type.
|
6
|
ToDouble
Converts a
type to a double type.
|
7
|
ToInt16
Converts a
type to a 16-bit integer.
|
8
|
ToInt32
Converts a
type to a 32-bit integer.
|
9
|
ToInt64
Converts a
type to a 64-bit integer.
|
10
|
ToSbyte
Converts a
type to a signed byte type.
|
11
|
ToSingle
Converts a
type to a small floating point number.
|
12
|
ToString
Converts a
type to a string.
|
13
|
ToType
Converts a
type to a specified type.
|
14
|
ToUInt16
Converts a
type to an unsigned int type.
|
15
|
ToUInt32
Converts a
type to an unsigned long type.
|
16
|
ToUInt64
Converts a
type to an unsigned big integer.
|
Materiały:
https://msdn.microsoft.com/en-us/library/ms228360%28v=vs.90%29.aspx
https://www.develop.com/us/tutorials/csharp/tutorialtopics/DotNet/CSharp/Basics/Basics.htm
http://www.tutorialspoint.com/csharp/csharp_data_types.htm
http://zetcode.com/lang/csharp/datatypes/
http://timtrott.co.uk/data-types-ranges/
https://msdn.microsoft.com/en-us/library/ms173104%28v=vs.90%29.aspx
http://zetcode.com/lang/csharp/datatypes/
http://www.tutorialspoint.com/csharp/csharp_type_conversion.htm
http://pawjershauge.blogspot.com/2010/03/clr-data-types-and-more.html
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384264%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/ya5y69ds%28VS.80%29.aspx
https://msdn.microsoft.com/en-us/library/1dhd7f2x%28v=vs.90%29.aspx
Brak komentarzy:
Prześlij komentarz