|
312 | 312 |
|
313 | 313 | This constructor exposes the underlying stream that <xref:System.IO.MemoryStream.GetBuffer%2A> returns. |
314 | 314 |
|
315 | | -
|
316 | | -
|
317 | 315 | ## Examples |
318 | 316 | This code example is part of a larger example provided for the <xref:System.IO.MemoryStream> class. |
319 | 317 |
|
|
452 | 450 | <format type="text/markdown"><![CDATA[ |
453 | 451 |
|
454 | 452 | ## Remarks |
455 | | - The <xref:System.IO.MemoryStream.CanRead%2A>, <xref:System.IO.MemoryStream.CanSeek%2A>, and <xref:System.IO.MemoryStream.CanWrite%2A> properties are all set to `true`, but the capacity cannot be changed. <xref:System.IO.MemoryStream.Capacity%2A> is set to `count`. |
| 453 | + The <xref:System.IO.MemoryStream.CanRead>, <xref:System.IO.MemoryStream.CanSeek>, and <xref:System.IO.MemoryStream.CanWrite> properties are all set to `true`, but the capacity cannot be changed. <xref:System.IO.MemoryStream.Capacity%2A> is set to `count`. |
456 | 454 |
|
457 | 455 | The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see <xref:System.IO.MemoryStream.SetLength%2A>). |
458 | 456 |
|
|
527 | 525 | <format type="text/markdown"><![CDATA[ |
528 | 526 |
|
529 | 527 | ## Remarks |
530 | | - The <xref:System.IO.MemoryStream.CanRead%2A> and <xref:System.IO.MemoryStream.CanSeek%2A> properties are both set to `true`. <xref:System.IO.MemoryStream.Capacity%2A> is set to `count`. |
| 528 | + The <xref:System.IO.MemoryStream.CanRead> and <xref:System.IO.MemoryStream.CanSeek> properties are both set to `true`. <xref:System.IO.MemoryStream.Capacity> is set to `count`. |
531 | 529 |
|
532 | 530 | The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see <xref:System.IO.MemoryStream.SetLength%2A>). |
533 | 531 |
|
|
604 | 602 | <format type="text/markdown"><![CDATA[ |
605 | 603 |
|
606 | 604 | ## Remarks |
607 | | - The <xref:System.IO.MemoryStream.CanRead%2A> and <xref:System.IO.MemoryStream.CanSeek%2A> properties are both set to `true`. <xref:System.IO.MemoryStream.Capacity%2A> is set to `count`. |
| 605 | + The <xref:System.IO.MemoryStream.CanRead> and <xref:System.IO.MemoryStream.CanSeek> properties are both set to `true`. <xref:System.IO.MemoryStream.Capacity> is set to `count`. |
608 | 606 |
|
609 | 607 | The new stream instance can be written to, but the <xref:System.IO.MemoryStream.Capacity%2A> of the underlying byte array cannot be changed. The length of the stream cannot be set to a value greater than the initial length of the specified byte array; however, the stream can be truncated (see <xref:System.IO.MemoryStream.SetLength%2A>). |
610 | 608 |
|
@@ -1029,20 +1027,23 @@ Refer to the <xref:System.IO.Stream.BeginWrite%2A> remarks for additional usage |
1029 | 1027 | <remarks> |
1030 | 1028 | <format type="text/markdown"><![CDATA[ |
1031 | 1029 |
|
1032 | | -## Remarks |
1033 | | - `Capacity` is the buffer length for system-provided byte arrays. `Capacity` cannot be set to a value less than the current length of the stream. |
1034 | | -
|
1035 | | -
|
| 1030 | +`Capacity` is the buffer length for system-provided byte arrays. `Capacity` cannot be set to a value less than the current length of the stream. |
1036 | 1031 |
|
1037 | 1032 | ## Examples |
1038 | | - This code example is part of a larger example provided for the <xref:System.IO.MemoryStream> class. |
1039 | 1033 |
|
1040 | | - :::code language="csharp" source="~/snippets/csharp/System.IO/MemoryStream/Overview/memstream.cs" id="Snippet5"::: |
1041 | | - :::code language="vb" source="~/snippets/visualbasic/System.IO/MemoryStream/Overview/memstream.vb" id="Snippet5"::: |
| 1034 | +This code example is part of a larger example provided for the <xref:System.IO.MemoryStream> class. |
| 1035 | +
|
| 1036 | +:::code language="csharp" source="~/snippets/csharp/System.IO/MemoryStream/Overview/memstream.cs" id="Snippet5"::: |
| 1037 | +:::code language="vb" source="~/snippets/visualbasic/System.IO/MemoryStream/Overview/memstream.vb" id="Snippet5"::: |
1042 | 1038 |
|
1043 | 1039 | ]]></format> |
1044 | 1040 | </remarks> |
1045 | | - <exception cref="T:System.ArgumentOutOfRangeException">A capacity is set that is negative or less than the current length of the stream.</exception> |
| 1041 | + <exception cref="T:System.ArgumentOutOfRangeException">A capacity is set that is negative or less than the current length of the stream. |
| 1042 | + |
| 1043 | +-or- |
| 1044 | + |
| 1045 | +In .NET 11 and later versions, the value being set is greater than 0x7FFFFFC7 bytes. |
| 1046 | + </exception> |
1046 | 1047 | <exception cref="T:System.ObjectDisposedException">The current stream is closed.</exception> |
1047 | 1048 | <exception cref="T:System.NotSupportedException"> |
1048 | 1049 | <see langword="set" /> is invoked on a stream whose capacity cannot be modified.</exception> |
@@ -1546,9 +1547,9 @@ The pending operation does not support writing.</exception> |
1546 | 1547 | ## Remarks |
1547 | 1548 | Because any data written to a <xref:System.IO.MemoryStream> object is written into RAM, this method is redundant. |
1548 | 1549 |
|
1549 | | - If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status%2A> property. |
| 1550 | + If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status> property. |
1550 | 1551 |
|
1551 | | - You can create a cancellation token by creating an instance of the <xref:System.Threading.CancellationTokenSource> class and passing the <xref:System.Threading.CancellationTokenSource.Token%2A> property as the `cancellationToken` parameter. |
| 1552 | + You can create a cancellation token by creating an instance of the <xref:System.Threading.CancellationTokenSource> class and passing the <xref:System.Threading.CancellationTokenSource.Token> property as the `cancellationToken` parameter. |
1552 | 1553 |
|
1553 | 1554 | This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.IO.MemoryStream.Flush>. |
1554 | 1555 |
|
@@ -2077,9 +2078,9 @@ The pending operation does not support writing.</exception> |
2077 | 2078 | <format type="text/markdown"><![CDATA[ |
2078 | 2079 |
|
2079 | 2080 | ## Remarks |
2080 | | - If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status%2A> property. |
| 2081 | + If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status> property. |
2081 | 2082 |
|
2082 | | - You can create a cancellation token by creating an instance of the <xref:System.Threading.CancellationTokenSource> class and passing the <xref:System.Threading.CancellationTokenSource.Token%2A> property as the `cancellationToken` parameter. |
| 2083 | + You can create a cancellation token by creating an instance of the <xref:System.Threading.CancellationTokenSource> class and passing the <xref:System.Threading.CancellationTokenSource.Token> property as the `cancellationToken` parameter. |
2083 | 2084 |
|
2084 | 2085 | This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.IO.MemoryStream.Read(System.Byte[],System.Int32,System.Int32)>. |
2085 | 2086 |
|
@@ -2229,7 +2230,7 @@ The pending operation does not support writing.</exception> |
2229 | 2230 |
|
2230 | 2231 | Seeking to any location beyond the length of the stream is supported. |
2231 | 2232 |
|
2232 | | - Do not use the <xref:System.IO.MemoryStream.Seek%2A> method to determine the new position in the stream if the <xref:System.IO.MemoryStream> was initialized with a non-zero offset. If you do, <xref:System.IO.MemoryStream.Seek%2A> will return an inaccurate value. Instead, use the <xref:System.IO.MemoryStream.Position%2A> property to get the new position of the stream. |
| 2233 | + Do not use the <xref:System.IO.MemoryStream.Seek%2A> method to determine the new position in the stream if the <xref:System.IO.MemoryStream> was initialized with a non-zero offset. If you do, <xref:System.IO.MemoryStream.Seek%2A> will return an inaccurate value. Instead, use the <xref:System.IO.MemoryStream.Position> property to get the new position of the stream. |
2233 | 2234 |
|
2234 | 2235 |
|
2235 | 2236 |
|
@@ -2303,28 +2304,35 @@ The pending operation does not support writing.</exception> |
2303 | 2304 | <Parameter Name="value" Type="System.Int64" /> |
2304 | 2305 | </Parameters> |
2305 | 2306 | <Docs> |
2306 | | - <param name="value">The value at which to set the length.</param> |
| 2307 | + <param name="value">The length to set.</param> |
2307 | 2308 | <summary>Sets the length of the current stream to the specified value.</summary> |
2308 | 2309 | <remarks> |
2309 | 2310 | <format type="text/markdown"><![CDATA[ |
2310 | 2311 |
|
2311 | | -## Remarks |
2312 | | - This method overrides <xref:System.IO.Stream.SetLength%2A>. |
| 2312 | +This method overrides <xref:System.IO.Stream.SetLength%2A>. |
2313 | 2313 |
|
2314 | | - If the specified value is less than the current length of the stream, the stream is truncated. If after the truncation the current position within the stream is past the end of the stream, the <xref:System.IO.MemoryStream.ReadByte%2A> method returns -1, the <xref:System.IO.MemoryStream.Read%2A> method reads zero bytes into the provided byte array, and <xref:System.IO.MemoryStream.Write%2A> and <xref:System.IO.MemoryStream.WriteByte%2A> methods append specified bytes at the end of the stream, increasing its length. If the specified value is larger than the current capacity and the stream is resizable, the capacity is increased, and the current position within the stream is unchanged. If the length is increased, the contents of the stream between the old and the new length are initialized to zeros. |
| 2314 | +If the specified value is less than the current length of the stream, the stream is truncated. If after the truncation the current position within the stream is past the end of the stream, the <xref:System.IO.MemoryStream.ReadByte%2A> method returns -1, the <xref:System.IO.MemoryStream.Read%2A> method reads zero bytes into the provided byte array, and <xref:System.IO.MemoryStream.Write%2A> and <xref:System.IO.MemoryStream.WriteByte%2A> methods append specified bytes at the end of the stream, increasing its length. If the specified value is larger than the current capacity and the stream is resizable, the capacity is increased, and the current position within the stream is unchanged. If the length is increased, the contents of the stream between the old and the new length are initialized to zeros. |
2315 | 2315 |
|
2316 | 2316 | > [!NOTE] |
2317 | | -> A <xref:System.IO.MemoryStream> instance must support writing for this method to work. Use the <xref:System.IO.MemoryStream.CanWrite%2A> property to determine whether the current instance supports writing. For additional information, see <xref:System.IO.Stream.CanWrite%2A>. |
| 2317 | +> A <xref:System.IO.MemoryStream> instance must support writing for this method to work. Use the <xref:System.IO.MemoryStream.CanWrite> property to determine whether the current instance supports writing. For additional information, see <xref:System.IO.Stream.CanWrite>. |
2318 | 2318 |
|
2319 | 2319 | ]]></format> |
2320 | 2320 | </remarks> |
2321 | 2321 | <exception cref="T:System.NotSupportedException">The current stream is not resizable and <paramref name="value" /> is larger than the current capacity. |
2322 | 2322 |
|
2323 | | - -or- |
| 2323 | +-or- |
2324 | 2324 |
|
2325 | | - The current stream does not support writing.</exception> |
| 2325 | +The current stream does not support writing.</exception> |
2326 | 2326 | <exception cref="T:System.ArgumentOutOfRangeException"> |
2327 | | - <paramref name="value" /> is negative or is greater than the maximum length of the <see cref="T:System.IO.MemoryStream" />, where the maximum length is (<see cref="F:System.Int32.MaxValue">Int32.MaxValue</see> - <code>origin</code>), and <code>origin</code> is the index into the underlying buffer at which the stream starts.</exception> |
| 2327 | + <paramref name="value" /> is negative |
| 2328 | + |
| 2329 | +-or- |
| 2330 | + |
| 2331 | +In .NET 11 and later versions, <paramref name="value" /> is greater than 0x7FFFFFC7 bytes. |
| 2332 | + |
| 2333 | +-or- |
| 2334 | + |
| 2335 | +In .NET 10 and earlier versions, <paramref name="value" /> is greater than the maximum length of the <see cref="T:System.IO.MemoryStream" />, where the maximum length is (<see cref="F:System.Int32.MaxValue">Int32.MaxValue</see> - <code>origin</code>), and <code>origin</code> is the index into the underlying buffer at which the stream starts.</exception> |
2328 | 2336 | <related type="Article" href="/dotnet/standard/io/">File and Stream I/O</related> |
2329 | 2337 | <related type="Article" href="/dotnet/standard/io/how-to-read-text-from-a-file">How to: Read Text from a File</related> |
2330 | 2338 | <related type="Article" href="/dotnet/standard/io/how-to-write-text-to-a-file">How to: Write Text to a File</related> |
@@ -2390,10 +2398,10 @@ The pending operation does not support writing.</exception> |
2390 | 2398 | ## Remarks |
2391 | 2399 | This method omits unused bytes in <xref:System.IO.MemoryStream> from the array. To get the entire buffer, use the <xref:System.IO.MemoryStream.GetBuffer%2A> method. |
2392 | 2400 |
|
2393 | | - This method returns a copy of the contents of the <xref:System.IO.MemoryStream> as a byte array. If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned. See the <xref:System.IO.MemoryStream.%23ctor%2A> constructor for details. |
| 2401 | + This method returns a copy of the contents of the <xref:System.IO.MemoryStream> as a byte array. If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned. See the <xref:System.IO.MemoryStream.%23ctor*> constructor for details. |
2394 | 2402 |
|
2395 | 2403 | > [!NOTE] |
2396 | | -> This method works when the <xref:System.IO.MemoryStream> is closed. |
| 2404 | +> This method works when the <xref:System.IO.MemoryStream> is closed. |
2397 | 2405 |
|
2398 | 2406 | ]]></format> |
2399 | 2407 | </remarks> |
@@ -2741,9 +2749,9 @@ The underlying buffer will not be exposed if the current `MemoryStream` instance |
2741 | 2749 | <format type="text/markdown"><![CDATA[ |
2742 | 2750 |
|
2743 | 2751 | ## Remarks |
2744 | | - If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status%2A> property. |
| 2752 | + If the operation is canceled before it completes, the returned task contains the <xref:System.Threading.Tasks.TaskStatus.Canceled> value for the <xref:System.Threading.Tasks.Task.Status> property. |
2745 | 2753 |
|
2746 | | - You can create a cancellation token by creating an instance of the <xref:System.Threading.CancellationTokenSource> class and passing the <xref:System.Threading.CancellationTokenSource.Token%2A> property as the `cancellationToken` parameter. |
| 2754 | + You can create a cancellation token by creating an instance of the <xref:System.Threading.CancellationTokenSource> class and passing the <xref:System.Threading.CancellationTokenSource.Token> property as the `cancellationToken` parameter. |
2747 | 2755 |
|
2748 | 2756 | This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as <xref:System.ArgumentException>, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by <xref:System.IO.MemoryStream.Write(System.Byte[],System.Int32,System.Int32)>. |
2749 | 2757 |
|
|
0 commit comments