Skip to content

Commit cf5a3d9

Browse files
authored
Markdownlint final fixes (#532)
* enable MD031 * Blank lines surrounding samples
1 parent 9b81805 commit cf5a3d9

17 files changed

+1174
-5
lines changed

.markdownlint.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@
1111
"code_blocks": false,
1212
"names": [
1313
]
14-
},
15-
16-
"MD031" : false
14+
}
1715
}

standard/arrays.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ An array has a rank that determines the number of indices associated with each a
99
The element type of an array can itself be an array type ([§16.2.1](arrays.md#1621-general)). Such arrays of arrays are distinct from multi-dimensional arrays and can be used to represent “jagged arrays”.
1010

1111
> *Example*:
12+
>
1213
> ```csharp
1314
> int[][] pascals =
1415
> {
@@ -18,6 +19,7 @@ The element type of an array can itself be an array type ([§16.2.1](arrays.md#1
1819
> new int[] {1, 3, 3, 1}
1920
> };
2021
> ```
22+
>
2123
> *end example*
2224
2325
Every array type is a reference type ([§8.2](types.md#82-reference-types)). The element type of an array can be any type, including value types and array types.
@@ -60,6 +62,7 @@ A single-dimensional array `T[]` implements the interface System.Collections.Gen
6062
Similarly, a single-dimensional array `T[]` also implements the interface `System.Collections.Generic.IReadOnlyList<T>` (`IReadOnlyList<T>` for short) and its base interfaces. Accordingly, there is an implicit conversion from `T[]` to `IReadOnlyList<T>` and its base interfaces. In addition, if there is an implicit reference conversion from `S` to `T` then `S[]` implements `IReadOnlyList<T>` and there is an implicit reference conversion from `S[]` to `IReadOnlyList<T>` and its base interfaces ([§10.2.8](conversions.md#1028-implicit-reference-conversions)). If there is an explicit reference conversion from `S` to `T` then there is an explicit reference conversion from `S[]` to `IReadOnlyList<T>` and its base interfaces ([§10.3.5](conversions.md#1035-explicit-reference-conversions)).
6163
6264
> *Example*: For example:
65+
>
6366
> ```csharp
6467
> using System.Collections.Generic;
6568
>
@@ -88,6 +91,7 @@ Similarly, a single-dimensional array `T[]` also implements the interface `Syste
8891
> }
8992
> }
9093
> ```
94+
>
9195
> The assignment `lst2 = oa1` generates a compile-time error since the conversion from `object[]` to `IList<string>` is an explicit conversion, not implicit. The cast `(IList<string>)oa1` will cause an exception to be thrown at run-time since `oa1` references an `object[]` and not a `string[]`. However the cast (`IList<string>)oa2` will not cause an exception to be thrown since `oa2` references a `string[]`. *end example*
9296
9397
Whenever there is an implicit or explicit reference conversion from `S[]` to `IList<T>`, there is also an explicit reference conversion from `IList<T>` and its base interfaces to `S[]` ([§10.3.5](conversions.md#1035-explicit-reference-conversions)).
@@ -121,6 +125,7 @@ For any two *reference_type*s `A` and `B`, if an implicit reference conversion
121125
Because of array covariance, assignments to elements of reference type arrays include a run-time check which ensures that the value being assigned to the array element is actually of a permitted type ([§11.18.2](expressions.md#11182-simple-assignment)).
122126
123127
> *Example*:
128+
>
124129
> ```csharp
125130
> class Test
126131
> {
@@ -141,6 +146,7 @@ Because of array covariance, assignments to elements of reference type arrays in
141146
> }
142147
> }
143148
> ```
149+
>
144150
> The assignment to `array[i]` in the `Fill` method implicitly includes a run-time check, which ensures that `value` is either a `null` reference or a reference to an object of a type that is compatible with the actual element type of `array`. In `Main`, the first two invocations of `Fill` succeed, but the third invocation causes a `System.ArrayTypeMismatchException` to be thrown upon executing the first assignment to `array[i]`. The exception occurs because a boxed `int` cannot be stored in a `string` array. *end example*
145151
146152
Array covariance specifically does not extend to arrays of *value_type*s. For example, no conversion exists that permits an `int[]` to be treated as an `object[]`.
@@ -164,67 +170,84 @@ variable_initializer
164170
| array_initializer
165171
;
166172
```
173+
167174
An array initializer consists of a sequence of variable initializers, enclosed by “`{`” and “`}`” tokens and separated by “`,`” tokens. Each variable initializer is an expression or, in the case of a multi-dimensional array, a nested array initializer.
168175

169176
The context in which an array initializer is used determines the type of the array being initialized. In an array creation expression, the array type immediately precedes the initializer, or is inferred from the expressions in the array initializer. In a field or variable declaration, the array type is the type of the field or variable being declared. When an array initializer is used in a field or variable declaration,
170177

171178
```csharp
172179
int[] a = {0, 2, 4, 6, 8};
173180
```
181+
174182
it is simply shorthand for an equivalent array creation expression:
175183

176184
```csharp
177185
int[] a = new int[] {0, 2, 4, 6, 8};
178186
```
187+
179188
For a single-dimensional array, the array initializer shall consist of a sequence of expressions, each having an implicit conversion to the element type of the array ([§10.2](conversions.md#102-implicit-conversions)). The expressions initialize array elements in increasing order, starting with the element at index zero. The number of expressions in the array initializer determines the length of the array instance being created.
180189

181190
> *Example*: The array initializer above creates an `int[]` instance of length 5 and then initializes the instance with the following values:
191+
>
182192
> ```csharp
183193
> a[0] = 0; a[1] = 2; a[2] = 4; a[3] = 6; a[4] = 8;
184194
> ```
195+
>
185196
> *end example*
186197
187198
For a multi-dimensional array, the array initializer shall have as many levels of nesting as there are dimensions in the array. The outermost nesting level corresponds to the leftmost dimension and the innermost nesting level corresponds to the rightmost dimension. The length of each dimension of the array is determined by the number of elements at the corresponding nesting level in the array initializer. For each nested array initializer, the number of elements shall be the same as the other array initializers at the same level.
188199
189200
> *Example*: The example:
201+
>
190202
> ```csharp
191203
> int[,] b = {{0, 1}, {2, 3}, {4, 5}, {6, 7}, {8, 9}};
192204
> ```
205+
>
193206
> creates a two-dimensional array with a length of five for the leftmost dimension and a length of two for the rightmost dimension:
207+
>
194208
> ```csharp
195209
> int[,] b = new int[5, 2];
196210
> ```
211+
>
197212
> and then initializes the array instance with the following values:
213+
>
198214
> ```csharp
199215
> b[0, 0] = 0; b[0, 1] = 1;
200216
> b[1, 0] = 2; b[1, 1] = 3;
201217
> b[2, 0] = 4; b[2, 1] = 5;
202218
> b[3, 0] = 6; b[3, 1] = 7;
203219
> b[4, 0] = 8; b[4, 1] = 9;
204220
> ```
221+
>
205222
> *end example*
206223
207224
If a dimension other than the rightmost is given with length zero, the subsequent dimensions are assumed to also have length zero.
208225
209226
> *Example*:
227+
>
210228
> ```csharp
211229
> int[,] c = {};
212230
> ```
231+
>
213232
> creates a two-dimensional array with a length of zero for both the leftmost and the rightmost dimension:
233+
>
214234
> ```csharp
215235
> int[,] c = new int[0, 0];
216236
> ```
237+
>
217238
> *end example*
218239
219240
When an array creation expression includes both explicit dimension lengths and an array initializer, the lengths shall be constant expressions and the number of elements at each nesting level shall match the corresponding dimension length.
220241
221242
> *Example*: Here are some examples:
243+
>
222244
> ```csharp
223245
> int i = 3;
224246
> int[] x = new int[3] {0, 1, 2}; // OK
225247
> int[] y = new int[i] {0, 1, 2}; // Error, i not a constant
226248
> int[] z = new int[3] {0, 1, 2, 3}; // Error, length/initializer mismatch
227249
> ```
250+
>
228251
> Here, the initializer for `y` results in a compile-time error because the dimension length expression is not a constant, and the initializer for `z` results in a compile-time error because the length and the number of elements in the initializer do not agree. *end example*
229252
<!-- markdownlint-disable MD028 -->
230253

0 commit comments

Comments
 (0)