Fixed size buffers in expressions
Member lookup (§7.3) of a fixed size buffer member proceeds exactly like member lookup of a field. A fixed size buffer can be referenced in an expression using a simple-name (§7.5.2) or a member-access (§7.5.4). When a fixed size buffer member is referenced as a simple name, the effect is the same as a member access of the form this.I, where I is the fixed size buffer member. In a member access of the form E.I, if E is of a struct type and a member lookup of I in that struct type identifies a fixed size member, then E.I is evaluated an classified as follows: · If the expression E.I does not occur in an unsafe context, a compile-time error occurs. · If E is classified as a value, a compile-time error occurs. · Otherwise, if E is a moveable variable (§18.3) and the expression E.I is not a fixed-pointer-initializer (§18.6), a compile-time error occurs. · Otherwise, E references a fixed variable and the result of the expression is a pointer to the first element of the fixed size buffer member I in E. The result is of type S*, where S is the element type of I, and is classified as a value. The subsequent elements of the fixed size buffer can be accessed using pointer operations from the first element. Unlike access to arrays, access to the elements of a fixed size buffer is an unsafe operation and is not range checked. The following example declares and uses a struct with a fixed size buffer member. unsafe struct Font class Test unsafe static void Main()
|