You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System.Collections.Generic/Dictionary`2.xml
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -458,6 +458,9 @@
458
458
459
459
460
460
461
+
> [!CAUTION]
462
+
> If `capacity` comes from user input, prefer using a constructor without a capacity parameter and letting the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
463
+
461
464
## Examples
462
465
The following code example creates a <xref:System.Collections.Generic.Dictionary%602> with a case-insensitive equality comparer for the current culture. The example adds four elements, some with lower-case keys and some with upper-case keys. The example then attempts to add an element with a key that differs from an existing key only by case, catches the resulting exception, and displays an error message. Finally, the example displays the elements in the dictionary.
463
466
@@ -526,7 +529,8 @@
526
529
527
530
This constructor is an O(1) operation.
528
531
529
-
532
+
> [!CAUTION]
533
+
> If `capacity` comes from user input, prefer using a constructor without a capacity parameter and letting the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
530
534
531
535
## Examples
532
536
The following code example creates a dictionary with an initial capacity of 4 and populates it with 4 entries.
@@ -1292,7 +1296,16 @@
1292
1296
<paramname="capacity">The number of entries.</param>
1293
1297
<summary>Ensures that the dictionary can hold up to a specified number of entries without any further expansion of its backing storage.</summary>
1294
1298
<returns>The current capacity of the <seecref="T:System.Collections.Generic.Dictionary`2" />.</returns>
1295
-
<remarks>To be added.</remarks>
1299
+
<remarks>
1300
+
<formattype="text/markdown"><![CDATA[
1301
+
1302
+
## Remarks
1303
+
1304
+
> [!CAUTION]
1305
+
> If `capacity` comes from user input, prefer letting the collection resize itself as elements are added instead of calling this method. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
Copy file name to clipboardExpand all lines: xml/System.Collections.Generic/HashSet`1.xml
+16-1Lines changed: 16 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -376,6 +376,9 @@ The following example demonstrates how to merge two disparate sets. This example
376
376
## Remarks
377
377
Since resizes are relatively expensive (require rehashing), this attempts to minimize the need to resize by setting the initial capacity based on the value of the `capacity`.
378
378
379
+
> [!CAUTION]
380
+
> If `capacity` comes from user input, prefer using a constructor overload without a `capacity` parameter, and let the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`), or verify that the element count matches the specified value.
381
+
379
382
]]></format>
380
383
</remarks>
381
384
</Docs>
@@ -506,6 +509,9 @@ The following example demonstrates how to merge two disparate sets. This example
506
509
## Remarks
507
510
Since resizes are relatively expensive (require rehashing), this attempts to minimize the need to resize by setting the initial capacity based on the value of the `capacity`.
508
511
512
+
> [!CAUTION]
513
+
> If `capacity` comes from user input, prefer using a constructor overload without a `capacity` parameter, and let the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`), or verify that the element count matches the specified value.
514
+
509
515
]]></format>
510
516
</remarks>
511
517
</Docs>
@@ -1230,7 +1236,16 @@ The following example demonstrates how to merge two disparate sets. This example
1230
1236
<paramname="capacity">The minimum capacity to ensure.</param>
1231
1237
<summary>Ensures that this hash set can hold the specified number of elements without any further expansion of its backing storage.</summary>
1232
1238
<returns>The new capacity of this instance.</returns>
1233
-
<remarks>To be added.</remarks>
1239
+
<remarks>
1240
+
<formattype="text/markdown"><![CDATA[
1241
+
1242
+
## Remarks
1243
+
1244
+
> [!CAUTION]
1245
+
> If `capacity` comes from user input, prefer letting the collection resize itself as elements are added instead of calling this method. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
Copy file name to clipboardExpand all lines: xml/System.Collections.Generic/List`1.xml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -320,6 +320,9 @@
320
320
321
321
This constructor is an O(1) operation.
322
322
323
+
> [!CAUTION]
324
+
> If `capacity` comes from user input, prefer using the parameterless constructor and letting the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
325
+
323
326
## Examples
324
327
The following example demonstrates the <xref:System.Collections.Generic.List%601.%23ctor%28System.Int32%29> constructor. A <xref:System.Collections.Generic.List%601> of strings with a capacity of 4 is created, because the ultimate size of the list is known to be exactly 4. The list is populated with four strings, and a read-only copy is created by using the <xref:System.Collections.Generic.List%601.AsReadOnly%2A> method.
325
328
@@ -1476,7 +1479,16 @@
1476
1479
<paramname="capacity">The minimum capacity to ensure.</param>
1477
1480
<summary>Ensures that the capacity of this list is at least the specified <paramrefname="capacity" />. If the current capacity is less than <paramrefname="capacity" />, it is increased to at least the specified <paramrefname="capacity" />.</summary>
1478
1481
<returns>The new capacity of this list.</returns>
1479
-
<remarks>To be added.</remarks>
1482
+
<remarks>
1483
+
<formattype="text/markdown"><![CDATA[
1484
+
1485
+
## Remarks
1486
+
1487
+
> [!CAUTION]
1488
+
> If `capacity` comes from user input, prefer letting the collection resize itself as elements are added instead of calling this method. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
Copy file name to clipboardExpand all lines: xml/System.Collections.Generic/Queue`1.xml
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -335,6 +335,9 @@
335
335
336
336
This constructor is an O(`n`) operation, where `n` is `capacity`.
337
337
338
+
> [!CAUTION]
339
+
> If `capacity` comes from user input, prefer using the parameterless constructor and letting the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
<paramname="capacity">The minimum capacity to ensure.</param>
843
846
<summary>Ensures that the capacity of this queue is at least the specified <paramrefname="capacity" />. If the current capacity is less than <paramrefname="capacity" />, it is increased to at least the specified <paramrefname="capacity" />.</summary>
844
847
<returns>The new capacity of this queue.</returns>
845
-
<remarks>To be added.</remarks>
848
+
<remarks>
849
+
<formattype="text/markdown"><![CDATA[
850
+
851
+
## Remarks
852
+
853
+
> [!CAUTION]
854
+
> If `capacity` comes from user input, prefer letting the collection resize itself as elements are added instead of calling this method. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
Copy file name to clipboardExpand all lines: xml/System.Collections/ArrayList.xml
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -354,6 +354,9 @@
354
354
355
355
This constructor is an `O(n)` operation, where `n` is `capacity`.
356
356
357
+
> [!CAUTION]
358
+
> If `capacity` comes from user input, prefer using the parameterless constructor and letting the collection resize as elements are added. If you must use a user-specified value, either clamp it to a reasonable limit (for example, `Math.Clamp(untrustedValue, 0, 20)`) or verify that the element count matches the specified value.
0 commit comments