class Test { static void Main() { unsafe { char* p = stackalloc char[256]; for (int i = 0; i < 256; i++) p[i] = (char)i; } } }a pointer element access is used to initialize the character buffer in a for loop. Because the operation P[E] is precisely equivalent to *(P + E), the example could equally well have been written:
class Test { static void Main() { unsafe { char* p = stackalloc char[256]; for (int i = 0; i < 256; i++) *(p + i) = (char)i; } } }end example] Paragraph 41 The pointer element access operator does not check for out-of-bounds errors and the behavior when accessing an out-of-bounds element is undefined. [Note: This is the same as C and C++. end note]
| |
Jagger Software Ltd | |
Company # 4070126 | |
VAT # 762 5213 42 |