C# Type Special Topic Study: A Complete Guide to Types

2019年8月21日 76点热度 0人点赞 2条评论
内容目录

Common Value Types

Value type variables can be directly assigned a value. They are derived from the class System.ValueType.

| Type | Description | Range | Default Value |
| :------ | :------------------------------------ | :------------------------------------------------------ | :------------ |
| bool | Boolean value | True or False | False |
| byte | 8-bit unsigned integer | 0 to 255 | 0 |
| char | 16-bit Unicode character | U+0000 to U+ffff | '\0' |
| decimal | 128-bit precise decimal value, 28-29 significant digits | (-7.9 x 10^28 to 7.9 x 10^28) / 100 to 28 | 0.0M |
| double | 64-bit double precision floating point | (+/-)5.0 x 10^-324 to (+/-)1.7 x 10^308 | 0.0D |
| float | 32-bit single precision floating point | -3.4 x 10^38 to +3.4 x 10^38 | 0.0F |
| int | 32-bit signed integer type | -2,147,483,648 to 2,147,483,647 | 0 |
| long | 64-bit signed integer type | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0L |
| sbyte | 8-bit signed integer type | -128 to 127 | 0 |
| short | 16-bit signed integer type | -32,768 to 32,767 | 0 |
| uint | 32-bit unsigned integer type | 0 to 4,294,967,295 | 0 |
| ulong | 64-bit unsigned integer type | 0 to 18,446,744,073,709,551,615 | 0 |
| ushort | 16-bit unsigned integer type | 0 to 65,535 | 0 |

Time Objects

They are all struct class types.

  • TimeSpan
  • DateTime
  • DateTimeOffset
  • DateTime2

| | DateTime | DateTime2 | DateTimeOffset |
| ------------------ | ------------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- |
| Date Range | 1753-01-01 to 9999-12-31 | 0001-01-01 to 9999-12-31 | 0001-01-01 to 9999-12-31 |
| Time Range | 00:00:00 to 23:59:59.997 | 00:00:00 to 23:59:59.9999999 | 00:00:00 to 23:59:59.9999999 |
| Storage Byte Size | 8 bytes | 6 bytes for precision less than 3; 7 bytes for precision 3 and 4; all other precisions require 8 bytes | 6 bytes for precision less than 3; 7 bytes for precision 3 and 4; all other precisions require 8 bytes |
| Precision | Rounded to .000, .003, or .007 seconds | 100 nanoseconds | 100 nanoseconds |
| Supports Custom Decimal Precision | No | Yes | Yes |
| Time Zone | None | None | -14:59 to +14:59 |

Collection Types
https://blog.csdn.net/zcaixzy5211314/article/details/80784329
Span
Memory
Figure 1: Non-allocating/non-copying conversions between Span-related types

| From | To | Mechanism |
| ----------------- | -------------------- | --------------------------------------------- |
| ArraySegment | Memory | Implicit conversion, AsMemory method |
| ArraySegment | ReadOnlyMemory | Implicit conversion, AsReadOnlyMemory method |
| ArraySegment | ReadOnlySpan | Implicit conversion, AsReadOnlySpan method |
| ArraySegment | Span | Implicit conversion, AsSpan method |
| ArraySegment | T[] | Array property |
| Memory | ArraySegment | TryGetArray method |
| Memory | ReadOnlyMemory | Implicit conversion, AsReadOnlyMemory method |
| Memory | Span | Span property |
| ReadOnlyMemory | ArraySegment | DangerousTryGetArray method |
| ReadOnlyMemory | ReadOnlySpan | Span property |
| ReadOnlySpan | ref readonly T | Indexer get value function, marshaling method |
| Span | ReadOnlySpan | Implicit conversion, AsReadOnlySpan method |
| Span | ref T | Indexer get value function, marshaling method |
| String | ReadOnlyMemory | AsReadOnlyMemory method |
| String | ReadOnlySpan | Implicit conversion, AsReadOnlySpan method |
| T[] | ArraySegment | Constructor, implicit conversion |
| T[] | Memory | Constructor, implicit conversion, AsMemory method |
| T[] | ReadOnlyMemory | Constructor, implicit conversion, AsReadOnlyMemory method |
| T[] | ReadOnlySpan | Constructor, implicit conversion, AsReadOnlySpan method |
| T[] | Span | Constructor, implicit conversion, AsSpan method |
| void* | ReadOnlySpan | Constructor |
| void* | Span | Constructor |

痴者工良

高级程序员劝退师

文章评论