diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml
index 6c3778e4be667..66dcfa3a48de6 100644
--- a/.github/workflows/scorecards.yml
+++ b/.github/workflows/scorecards.yml
@@ -71,6 +71,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@45775bd8235c68ba998cffa5171334d58593da47 # v3.28.15
+ uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
with:
sarif_file: results.sarif
diff --git a/docs/azure/includes/dotnet-all.md b/docs/azure/includes/dotnet-all.md
index 7f410b6419e81..b0686814d0f8e 100644
--- a/docs/azure/includes/dotnet-all.md
+++ b/docs/azure/includes/dotnet-all.md
@@ -444,7 +444,7 @@
| LUIS Authoring | NuGet [3.1.0](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring/3.1.0)
NuGet [3.2.0-preview.5](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring/3.2.0-preview.5) | | GitHub [3.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring_3.2.0-preview.3/sdk/cognitiveservices/Language.LUIS.Authoring) |
| LUIS Runtime | NuGet [3.1.0-preview.1](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime/3.1.0-preview.1) | | GitHub [3.1.0-preview.1](https://github.com/Azure/azure-sdk-for-net/tree/Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime_3.1.0-preview.1/sdk/cognitiveservices/Language.LUIS.Runtime) |
| Media Live Video Analytics Edge | NuGet [1.0.4-preview.1](https://www.nuget.org/packages/Microsoft.Azure.Media.LiveVideoAnalytics.Edge/1.0.4-preview.1) | | GitHub [1.0.4-preview.1](https://github.com/Azure/azure-sdk-for-net/tree/Microsoft.Azure.Media.LiveVideoAnalytics.Edge_1.0.4-preview.1/sdk/mediaservices/Microsoft.Azure.Media.LiveVideoAnalytics.Edge) |
-| Microsoft.Azure.Amqp | NuGet [2.6.9](https://www.nuget.org/packages/Microsoft.Azure.Amqp/2.6.9) | | |
+| Microsoft.Azure.Amqp | NuGet [2.6.11](https://www.nuget.org/packages/Microsoft.Azure.Amqp/2.6.11) | | |
| Microsoft.Azure.Devices | NuGet [1.40.0](https://www.nuget.org/packages/Microsoft.Azure.Devices/1.40.0)
NuGet [2.0.0-preview007](https://www.nuget.org/packages/Microsoft.Azure.Devices/2.0.0-preview007) | | |
| Microsoft.Azure.Devices.Authentication | NuGet [2.0.0-preview001](https://www.nuget.org/packages/Microsoft.Azure.Devices.Authentication/2.0.0-preview001) | | |
| Microsoft.Azure.Devices.Client.PCL | NuGet [1.0.16](https://www.nuget.org/packages/Microsoft.Azure.Devices.Client.PCL/1.0.16) | | |
@@ -552,11 +552,11 @@
| Microsoft.Azure.Functions.Worker.Extensions.ServiceBus | NuGet [5.22.2](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.ServiceBus/5.22.2) | | |
| Microsoft.Azure.Functions.Worker.Extensions.SignalRService | NuGet [2.0.1](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.SignalRService/2.0.1) | | |
| Microsoft.Azure.Functions.Worker.Extensions.Sql | NuGet [3.1.376](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Sql/3.1.376) | | |
-| Microsoft.Azure.Functions.Worker.Extensions.Storage | NuGet [6.6.1](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage/6.6.1) | | |
-| Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs | NuGet [6.6.1](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs/6.6.1) | | |
-| Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues | NuGet [5.5.1](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues/5.5.1) | | |
+| Microsoft.Azure.Functions.Worker.Extensions.Storage | NuGet [6.7.0](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage/6.7.0) | | |
+| Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs | NuGet [6.7.0](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs/6.7.0) | | |
+| Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues | NuGet [5.5.2](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues/5.5.2) | | |
| Microsoft.Azure.Functions.Worker.Extensions.Storage.Tables | NuGet [1.0.0-preview1](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Storage.Tables/1.0.0-preview1) | | |
-| Microsoft.Azure.Functions.Worker.Extensions.Tables | NuGet [1.4.2](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Tables/1.4.2) | | |
+| Microsoft.Azure.Functions.Worker.Extensions.Tables | NuGet [1.4.3](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Tables/1.4.3) | | |
| Microsoft.Azure.Functions.Worker.Extensions.Timer | NuGet [4.3.1](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Timer/4.3.1) | | |
| Microsoft.Azure.Functions.Worker.Extensions.Warmup | NuGet [4.0.2](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.Warmup/4.0.2) | | |
| Microsoft.Azure.Functions.Worker.Grpc | NuGet [2.0.0](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Grpc/2.0.0) | | |
diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md
index 7380d328c6e5e..e9ac7d2247509 100644
--- a/docs/core/compatibility/10.0.md
+++ b/docs/core/compatibility/10.0.md
@@ -2,7 +2,7 @@
title: Breaking changes in .NET 10
titleSuffix: ""
description: Navigate to the breaking changes in .NET 10.
-ms.date: 04/08/2025
+ms.date: 04/21/2025
ai-usage: ai-assisted
no-loc: [Blazor, Razor, Kestrel]
---
@@ -29,6 +29,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
| [ActivitySource.CreateActivity and ActivitySource.StartActivity behavior change](core-libraries/10.0/activity-sampling.md) | Behavioral change | Preview 1 |
| [C# 14 overload resolution with span parameters](core-libraries/10.0/csharp-overload-resolution.md) | Behavioral change | Preview 1 |
| [Consistent shift behavior in generic math](core-libraries/10.0/generic-math.md) | Behavioral change | Preview 1 |
+| [Default trace context propagator updated to W3C standard](core-libraries/10.0/default-trace-context-propagator.md) | Behavioral change | Preview 4 |
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
| [System.Linq.AsyncEnumerable included in core libraries](core-libraries/10.0/asyncenumerable.md) | Source incompatible | Preview 1 |
diff --git a/docs/core/compatibility/core-libraries/10.0/default-trace-context-propagator.md b/docs/core/compatibility/core-libraries/10.0/default-trace-context-propagator.md
new file mode 100644
index 0000000000000..5a7394ef77805
--- /dev/null
+++ b/docs/core/compatibility/core-libraries/10.0/default-trace-context-propagator.md
@@ -0,0 +1,55 @@
+---
+title: "Breaking change - Default trace context propagator updated to W3C standard"
+description: "Learn about the breaking change in .NET 10 where the default trace context propagator is switched from Legacy to W3C."
+ms.date: 4/21/2025
+ai-usage: ai-assisted
+ms.custom: https://github.com/dotnet/docs/issues/45793
+---
+
+# Default trace context propagator updated to W3C standard
+
+The default trace context propagator has been switched from the legacy propagator to the W3C propagator. The new propagator uses the `baggage` header instead of `Correlation-Context`, enforces W3C-compliant encoding, and supports only W3C-formatted trace parent IDs.
+
+## Version introduced
+
+.NET 10 Preview 4
+
+## Previous behavior
+
+The method returned an instance of the legacy propagator. By default, was set to this legacy instance.
+
+## New behavior
+
+The method now returns an instance of the W3C propagator. By default, is set to this W3C instance.
+
+Example of setting the default propagator to the legacy propagator:
+
+```csharp
+DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator();
+```
+
+## Type of breaking change
+
+This is a [behavioral change](../../categories.md#behavioral-change).
+
+## Reason for change
+
+This change ensures full compliance with the W3C Trace Context and Baggage specifications. The W3C propagator enforces strict formatting for trace parent, trace state, and baggage keys and values, aligning with the W3C standards. The legacy propagator was more lenient and used the non-standard `Correlation-Context` header for baggage propagation.
+
+For more details, see the following GitHub issues:
+
+- [Pull Request #114583](https://github.com/dotnet/runtime/pull/114583)
+- [Issue #114584](https://github.com/dotnet/runtime/issues/114584)
+
+## Recommended action
+
+If you need to retain the legacy behavior, use the `DistributedContextPropagator.CreatePreW3CPropagator()` method to retrieve the legacy propagator instance. Set it as the current propagator as shown below:
+
+```csharp
+DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator();
+```
+
+## Affected APIs
+
+-
+-
diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml
index 74a1a6e83698c..9a68a1eeca6c4 100644
--- a/docs/core/compatibility/toc.yml
+++ b/docs/core/compatibility/toc.yml
@@ -22,6 +22,8 @@ items:
href: core-libraries/10.0/csharp-overload-resolution.md
- name: Consistent shift behavior in generic math
href: core-libraries/10.0/generic-math.md
+ - name: Default trace context propagator updated to W3C Standard
+ href: core-libraries/10.0/default-trace-context-propagator.md
- name: LDAP DirectoryControl parsing is now more stringent
href: core-libraries/10.0/ldap-directorycontrol-parsing.md
- name: MacCatalyst version normalization
@@ -1390,6 +1392,8 @@ items:
href: core-libraries/10.0/csharp-overload-resolution.md
- name: Consistent shift behavior in generic math
href: core-libraries/10.0/generic-math.md
+ - name: Default trace context propagator updated to W3C Standard
+ href: core-libraries/10.0/default-trace-context-propagator.md
- name: LDAP DirectoryControl parsing is now more stringent
href: core-libraries/10.0/ldap-directorycontrol-parsing.md
- name: MacCatalyst version normalization
diff --git a/docs/core/containers/publish-configuration.md b/docs/core/containers/publish-configuration.md
index 2d56e9f4b3daa..9ef1af1e5f691 100644
--- a/docs/core/containers/publish-configuration.md
+++ b/docs/core/containers/publish-configuration.md
@@ -2,19 +2,19 @@
title: Containerize a .NET app reference
description: Reference material for containerizing a .NET app and configuring the container image.
ms.topic: reference
-ms.date: 01/27/2025
+ms.date: 04/22/2025
---
# Containerize a .NET app reference
-In this reference article, you learn how to configure the container image that's generated when you publish a .NET app as a container. This article covers the various properties that you can set to control the image, the execution environment, and the commands that are run when the container starts.
+In this reference article, you learn how to configure the container image generated when you publish a .NET app as a container. This article covers the various properties that you can set to control the image, the execution environment, and the commands that are run when the container starts.
## Configure container image
You can control many aspects of the generated container through MSBuild properties. In general, if you can use a command in a _Dockerfile_ to set some configuration, you can do the same via MSBuild.
> [!NOTE]
-> The only exceptions to this are `RUN` commands. Due to the way containers are built, those can't be emulated. If you need this functionality, you might consider using a _Dockerfile_ to build your container images.
+> The only exceptions to this are `RUN` commands. Due to the way containers are built, those commands can't be emulated. If you need this functionality, consider using a _Dockerfile_ to build your container images.
There's no way of performing `RUN` commands with the .NET SDK. These commands are often used to install some OS packages or create a new OS user, or any number of arbitrary things. If you would like to keep using the .NET SDK container building feature, you can instead create a custom base image with these changes and then using this base image. For more information, see [`ContainerBaseImage`](#containerbaseimage).
@@ -98,6 +98,18 @@ The preceding project configuration results in a final tag of `8.0-alpine` for a
This field is free-form, and often can be used to select different operating system distributions, default package configurations, or any other _flavor_ of changes to a base image. This field is ignored when `ContainerBaseImage` is set. For more information, see [.NET container images](../docker/container-images.md).
+### `ContainerPublishInParallel`
+
+For multi-RID containers, certain project types (like Blazor WebAssembly) may encounter build race conditions. To address this, starting with .NET SDK versions 8.0.408, 9.0.300, and 10.0, you can control the parallelism of the publish process using the `ContainerPublishInParallel` property. By default, publishing occurs in parallel for each Runtime Identifier (RID). Setting this property to `false` ensures sequential publishing, which increases stability but may take longer.
+
+```xml
+
+ false
+
+```
+
+For more information on multi-RID publishing, see [ContainerRuntimeIdentifier(s)](#containerruntimeidentifiers).
+
### `ContainerRuntimeIdentifier(s)`
The `ContainerRuntimeIdentifier` property specifies the OS and architecture for your container if the `ContainerBaseImage` supports multiple platforms. For example, the `mcr.microsoft.com/dotnet/runtime` image supports `linux-x64`, `linux-arm`, `linux-arm64`, and `win10-x64`. By default, this is set to the `RuntimeIdentifier` used when publishing the container. Typically, you don't need to set this property explicitly; instead, use the `-r` option with the `dotnet publish` command. If the chosen image doesn't support the specified `RuntimeIdentifier`, an error indicates the supported identifiers.
@@ -118,11 +130,16 @@ To specify multiple container runtime identifiers for multi-architecture images,
```
+> [!IMPORTANT]
+> The `ContainerRuntimeIdentifiers` property must be a subset of the `RuntimeIdentifiers` property. If this condition isn't met, critical parts of the build pipeline may fail.
+>
+> Setting multiple `ContainerRuntimeIdentifiers` results in a multi-architecture image being created. For more information, see [Multi-architecture images](#multi-architecture-images).
+
For more information regarding the runtime identifiers supported by .NET, see [RID catalog](../rid-catalog.md).
### `ContainerRegistry`
-The container registry property controls the destination registry, the place that the newly created image will be pushed to. By default it's pushed to the local Docker daemon, but you can also specify a remote registry. When using a remote registry that requires authentication, you authenticate using the well-known `docker login` mechanisms. For more information, See [authenticating to container registries](https://aka.ms/dotnet/containers/auth) for more details. For a concrete example of using this property, consider the following XML example:
+The container registry property controls the destination registry, the place that the newly created image is to be pushed to. By default it's pushed to the local Docker daemon, but you can also specify a remote registry. When using a remote registry that requires authentication, you authenticate using the well-known `docker login` mechanisms. For more information, See [authenticating to container registries](https://aka.ms/dotnet/containers/auth) for more details. For a concrete example of using this property, consider the following XML example:
```xml
@@ -154,18 +171,33 @@ The container repository is the name of the image itself, for example, `dotnet/r
Image names consist of one or more slash-delimited segments, each of which can only contain lowercase alphanumeric characters, periods, underscores, and dashes, and must start with a letter or number. Any other characters result in an error being thrown.
-### `ContainerImageTag(s)`
+### `ContainerImageFormat`
+
+Starting with .NET 8.0.405, you can use the `ContainerImageFormat` MSBuild property to specify the image format as either `Docker` or `OCI`. By default, the .NET tooling infers the format from the base image. For example, .NET base images use the Docker-specific format `application/vnd.docker.distribution.manifest.v2+json`. However, many modern tools prefer the OCI format `application/vnd.oci.image.manifest.v1+json`. To force a specific format, set the property as shown:
+
+```xml
+
+ OCI
+
+```
+
+Both formats are largely interchangeable without loss of information.
+
+> [!NOTE]
+> When building a multi-architecture image, the resulting image format is always OCI.
+
+### `ContainerImageTag`
The container image tag property controls the tags that are generated for the image. To specify a single tag use `ContainerImageTag` and for multiple tags use `ContainerImageTags`.
> [!IMPORTANT]
-> When you use `ContainerImageTags`, you'll end up with multiple images, one per unique tag.
+> When you use `ContainerImageTags`, you end up with multiple images, one per unique tag.
Tags are often used to refer to different versions of an app, but they can also refer to different operating system distributions, or even different configurations.
Starting with .NET 8, when a tag isn't provided the default is `latest`.
-To override the default, specify either of the following:
+To override the default, specify either of the following properties:
```xml
@@ -184,7 +216,7 @@ To specify multiple tags, use a semicolon-delimited set of tags in the `Containe
Tags can only contain up to 127 alphanumeric characters, periods, underscores, and dashes. They must start with an alphanumeric character or an underscore. Any other form results in an error being thrown.
> [!NOTE]
-> When using `ContainerImageTags` or any MSBuild property that needs to configure `;` delimited values. If you're calling `dotnet publish` from the command line (as is the case with most CI/CD environments), you need to understand the limitations of the environment's inability to disambiguate delimiters and quotations, thus requiring proper escaping. This differs between PowerShell and Bash. Consider the following `dotnet publish` commands in their respective environments:
+> When using `ContainerImageTags` or any MSBuild property requiring `;`-delimited values, ensure proper escaping when calling `dotnet publish` from the command line, especially in CI/CD environments. Escaping rules differ between PowerShell and Bash. For example:
>
> ```powershell
> dotnet publish --os linux --arch x64 /t:PublishContainer /p:ContainerImageTags=`"1.2.3-alpha2`;latest`"
@@ -283,6 +315,23 @@ For more information, see [.NET environment variables](../tools/dotnet-environme
> [!NOTE]
> It's currently not possible to set environment variables from the .NET CLI when publishing a container image. For more information, see [GitHub: .NET SDK container builds](https://github.com/dotnet/sdk-container-builds/issues/451).
+### `LocalRegistry`
+
+The `LocalRegistry` MSBuild property specifies the local container tooling to use when pushing to local sources. Supported values are `docker` and `podman`. If not set, the SDK determines the tool based on availability:
+
+- If both `docker` and `podman` exist, and `docker` is an alias for `podman`, then `podman` is used.
+- If only `docker` exists, `docker` is used.
+- If only `podman` exists, `podman` is used.
+- If neither exists, an error is thrown.
+
+To explicitly set the local registry tool, use the following configuration:
+
+```xml
+
+ podman
+
+```
+
## Configure container commands
By default, the container tools launch your app using either the generated AppHost binary for your app (if your app uses an AppHost), or the `dotnet` command plus your app's DLL.
@@ -293,7 +342,7 @@ These different configuration points exist because different base images use dif
- Identify the binary to run and set it as `ContainerAppCommand`
- Identify which arguments are _required_ for your application to run and set them as `ContainerAppCommandArgs`
-- Identify which arguments (if any) are _optional_ and could be overridden by a user and set them as `ContainerDefaultArgs`
+- Identify which arguments (if any) are _optional_ and are able to be overridden by a user and set them as `ContainerDefaultArgs`
- Set `ContainerAppCommandInstruction` to `DefaultArgs`
For more information, see the following configuration items.
@@ -317,7 +366,7 @@ The `ContainerAppCommand` configuration has a single `Include` property, which r
### `ContainerAppCommandArgs`
-This app command args configuration item represents any logically required arguments for your app that should be applied to the `ContainerAppCommand`. By default, none are generated for an app. When present, the args are applied to your container when it's run.
+This app command args configuration item represents any logically required arguments for your app that should be applied to the `ContainerAppCommand`. By default, none are generated for an app. When present, the args are applied to your container when it runs.
The `ContainerAppCommandArgs` configuration has a single `Include` property, which represents the option or argument to apply to the `ContainerAppCommand` command.
@@ -427,10 +476,26 @@ Where possible, existing MSBuild properties provide the values for these labels.
| `org.opencontainers.image.licenses` | | `ContainerLicenseExpression` | `PackageLicenseExpression` | `ContainerGenerateLabelsImageLicenses` | |
| `org.opencontainers.image.title` | | `ContainerTitle` | `Title` | `ContainerGenerateLabelsImageTitle` | |
| `org.opencontainers.image.base.name` | | `ContainerBaseImage` | | `ContainerGenerateLabelsImageBaseName` | |
-| `org.opencontainers.image.base.digest` | | | | `ContainerGenerateLabelsImageBaseDigest` | This will be the SHA digest of the chosen base image. Available from .NET SDK 9.0.100 onwards. |
+| `org.opencontainers.image.base.digest` | | | | `ContainerGenerateLabelsImageBaseDigest` | This is the SHA digest of the chosen base image. Available from .NET SDK 9.0.100 onwards. |
| `org.opencontainers.image.source` | | `PrivateRepositoryUrl` | | `ContainerGenerateLabelsImageSource` | Only written if `PublishRepositoryUrl` is `true`. Also relies on Sourcelink infrastructure being part of the build. |
| `org.opencontainers.image.revision` | | `SourceRevisionId` | | `ContainerGenerateLabelsImageRevision` | Only written if `PublishRepositoryUrl` is `true`. Also relies on Sourcelink infrastructure being part of the build. |
+## Multi-architecture images
+
+Multi-architecture images enable a single container image to support multiple architectures, simplifying cross-platform development and deployment. The .NET SDK supports this through the `ContainerRuntimeIdentifiers` property.
+
+Beginning with SDK versions 8.0.405, 9.0.102, and 9.0.2xx, multi-RID container publishing is supported. When publishing with `/t:PublishContainer`:
+
+- If a single `RuntimeIdentifier` or `ContainerRuntimeIdentifier` is specified, a single-architecture container is generated as before.
+- If no single `RuntimeIdentifier` is specified but multiple `RuntimeIdentifiers` or `ContainerRuntimeIdentifiers` are set, the SDK publishes the app for each specified RID and combines the resulting images into an [OCI Image Index](https://specs.opencontainers.org/image-spec/image-index/). This index allows multiple architecture-specific images to share a single name.
+
+> [!NOTE]
+> The `ContainerRuntimeIdentifiers` property must be a subset of the `RuntimeIdentifiers` property. For more information, see [ContainerRuntimeIdentifiers](#containerruntimeidentifiers).
+
+This feature streamlines container workflows in mixed-architecture environments. For example, a developer on a `linux-x64` host can publish a container supporting both `linux-x64` and `linux-arm64`, enabling deployment to either architecture without changing image names or labels.
+
+The generated OCI Image Index is widely supported with modern container tooling, enhancing compatibility and ease of use.
+
## See also
- [Containerize a .NET app with dotnet publish](sdk-publish.md)
diff --git a/docs/core/testing/mstest-analyzers/mstest0042.md b/docs/core/testing/mstest-analyzers/mstest0042.md
new file mode 100644
index 0000000000000..f4a05e30dd534
--- /dev/null
+++ b/docs/core/testing/mstest-analyzers/mstest0042.md
@@ -0,0 +1,41 @@
+---
+title: "MSTEST0042: Avoid duplicated 'DataRow' entries"
+description: "Learn about code analysis rule MSTEST0042: Avoid duplicated 'DataRow' entries"
+ms.date: 04/11/2025
+f1_keywords:
+- MSTEST0042
+- DuplicateDataRowAnalyzer
+helpviewer_keywords:
+- DuplicateDataRowAnalyzer
+- MSTEST0042
+author: Youssef1313
+ms.author: ygerges
+---
+# MSTEST0042: Avoid duplicated 'DataRow' entries
+
+| Property | Value |
+|-------------------------------------|------------------------------------------------------------------------|
+| **Rule ID** | MSTEST0042 |
+| **Title** | Avoid duplicated 'DataRow' entries |
+| **Category** | Usage |
+| **Fix is breaking or non-breaking** | Non-breaking |
+| **Enabled by default** | Yes |
+| **Default severity** | Warning |
+| **Introduced in version** | 3.9.0 |
+| **Is there a code fix** | No |
+
+## Cause
+
+A test method has two or more [DataRow](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute) attributes that are equivalent.
+
+## Rule description
+
+ is used to denote inputs to test methods. It's not expected that a test will intentionally run twice with the exact same data. Duplicated `DataRow`s are often a copy/paste error.
+
+## How to fix violations
+
+Either remove the duplicate `DataRow` attribute, or fix it to make unique.
+
+## When to suppress warnings
+
+Do not suppress a warning from this rule, unless you intended to use the same input more than once.
diff --git a/docs/core/testing/mstest-analyzers/mstest0043.md b/docs/core/testing/mstest-analyzers/mstest0043.md
new file mode 100644
index 0000000000000..914e17e0d4128
--- /dev/null
+++ b/docs/core/testing/mstest-analyzers/mstest0043.md
@@ -0,0 +1,41 @@
+---
+title: "MSTEST0043: Use retry attribute on test method"
+description: "Learn about code analysis rule MSTEST0043: Use retry attribute on test method"
+ms.date: 04/11/2025
+f1_keywords:
+- MSTEST0043
+- UseRetryWithTestMethodAnalyzer
+helpviewer_keywords:
+- UseRetryWithTestMethodAnalyzer
+- MSTEST0043
+author: Youssef1313
+ms.author: ygerges
+---
+# MSTEST0043: Use retry attribute on test method
+
+| Property | Value |
+|-------------------------------------|------------------------------------------------------------------------------------------|
+| **Rule ID** | MSTEST0043 |
+| **Title** | Use retry attribute on test method |
+| **Category** | Usage |
+| **Fix is breaking or non-breaking** | Non-breaking |
+| **Enabled by default** | Yes |
+| **Default severity** | Warning (escalated to Error when setting `MSTestAnalysisMode` to `Recommended` or `All`) |
+| **Introduced in version** | 3.9.0 |
+| **Is there a code fix** | No |
+
+## Cause
+
+A method has an attribute that derives from and does not have an attribute that derives from .
+
+## Rule description
+
+ only applies to test methods.
+
+## How to fix violations
+
+Add to the method, or remove the .
+
+## When to suppress warnings
+
+Do not suppress a warning from this rule.
diff --git a/docs/core/testing/mstest-analyzers/overview.md b/docs/core/testing/mstest-analyzers/overview.md
index d8bd11d084fe9..04df8a6d0c1b9 100644
--- a/docs/core/testing/mstest-analyzers/overview.md
+++ b/docs/core/testing/mstest-analyzers/overview.md
@@ -49,11 +49,17 @@ This setting follows the default documented behavior for each rule.
### `Recommended`
-This is the mode we expect most developers to use. Rules that are enabled by default with Info (`suggestion`) severity are escalated to warnings. Moreover, certain rules might be escalated to errors in both `Recommended` and `All` modes. For example, [MSTEST0003: Test methods should have valid layout](mstest0003.md) is escalated to error in `Recommended` and `All` modes.
+This is the mode most developers are expected to use. Rules that are enabled by default with Info (`suggestion`) severity are escalated to warnings. The following rules are escalated to errors in both `Recommended` and `All` modes:
+
+- [MSTEST0003: Test methods should have valid layout](mstest0003.md).
+- [MSTEST0043: Use retry attribute on test method](mstest0043.md).
### `All`
-This mode is more aggressive than `Recommended`. All rules are enabled as warnings. As mentioned for `Recommended` mode, certain rules might be escalated to errors in both `Recommended` and `All` modes. For example, [MSTEST0003: Test methods should have valid layout](./mstest0003.md) is escalated to error in `Recommended` and `All` modes.
+This mode is more aggressive than `Recommended`. All rules are enabled as warnings. In addition, the following rules are escalated to errors:
+
+- [MSTEST0003: Test methods should have valid layout](mstest0003.md).
+- [MSTEST0043: Use retry attribute on test method](mstest0043.md).
> [!NOTE]
> The following rules are completely opt-in and are not enabled in `Default`, `Recommended`, or `All` modes:
diff --git a/docs/core/testing/mstest-analyzers/usage-rules.md b/docs/core/testing/mstest-analyzers/usage-rules.md
index 120458aad2c48..8f6723072467a 100644
--- a/docs/core/testing/mstest-analyzers/usage-rules.md
+++ b/docs/core/testing/mstest-analyzers/usage-rules.md
@@ -38,3 +38,5 @@ Identifier | Name | Description
[MSTEST0039](mstest0039.md) | UseNewerAssertThrowsAnalyzer | Use newer 'Assert.Throws' methods
[MSTEST0040](mstest0040.md) | AvoidUsingAssertsInAsyncVoidContextAnalyzer | Do not assert inside 'async void' contexts
[MSTEST0041](mstest0041.md) | UseConditionBaseWithTestClassAnalyzer | Use 'ConditionBaseAttribute' on test classes
+[MSTEST0042](mstest0042.md) | DuplicateDataRowAnalyzer | Avoid duplicated 'DataRow' entries
+[MSTEST0043](mstest0043.md) | UseRetryWithTestMethodAnalyzer | Use retry attribute on test method
diff --git a/docs/csharp/programming-guide/classes-and-structs/extension-methods.md b/docs/csharp/programming-guide/classes-and-structs/extension-methods.md
index 9b0d992b25127..c568b72a3d92e 100644
--- a/docs/csharp/programming-guide/classes-and-structs/extension-methods.md
+++ b/docs/csharp/programming-guide/classes-and-structs/extension-methods.md
@@ -12,9 +12,9 @@ helpviewer_keywords:
Extension members enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.
-<< Introduce both types. >>
+Beginning with C# 14, there are two syntaxes you use to define extension methods. C# 14 adds [`extension`](../../language-reference/keywords/extension.md) containers, where you define multiple extension members for a type or an instance of a type. Before C# 14, you add the [`this`](../../language-reference/keywords/this.md) modifier to the first parameter of a static method to indicate that the method appears as a member of an instance of the parameter type.
-<< Add Extension member lowering here>>. Extension methods are static methods, but they're called as if they were instance methods on the extended type. For client code written in C#, F# and Visual Basic, there's no apparent difference between calling an extension method and the methods defined in a type.
+Extension methods are static methods, but they're called as if they were instance methods on the extended type. For client code written in C#, F# and Visual Basic, there's no apparent difference between calling an extension method and the methods defined in a type. Both forms of extension methods are compiled to the same IL (Intermediate Language). Consumers of extension members don't need to know which syntax was used to define extension methods.
The most common extension members are the LINQ standard query operators that add query functionality to the existing and types. To use the standard query operators, first bring them into scope with a `using System.Linq` directive. Then any type that implements appears to have instance methods such as , , , and so on. You can see these extra methods in IntelliSense statement completion when you type "dot" after an instance of an type such as or .
@@ -134,13 +134,13 @@ For more information on derived types, see [Inheritance](../../fundamentals/obje
If you do implement extension methods for a given type, remember the following points:
- An extension method isn't called if it has the same signature as a method defined in the type.
-- Extension methods are brought into scope at the namespace level. For example, if you have multiple static classes that contain extension methods in a single namespace named `Extensions`, they'll all be brought into scope by the `using Extensions;` directive.
+- Extension methods are brought into scope at the namespace level. For example, if you have multiple static classes that contain extension methods in a single namespace named `Extensions`, all of them are brought into scope by the `using Extensions;` directive.
For a class library that you implemented, you shouldn't use extension methods to avoid incrementing the version number of an assembly. If you want to add significant functionality to a library for which you own the source code, follow the .NET guidelines for assembly versioning. For more information, see [Assembly Versioning](../../../standard/assembly/versioning.md).
## See also
-- [Parallel Programming Samples (these include many example extension methods)](/samples/browse/?products=dotnet&term=parallel)
+- [Parallel Programming Samples (many examples demonstrate extension methods)](/samples/browse/?products=dotnet&term=parallel)
- [Lambda Expressions](../../language-reference/operators/lambda-expressions.md)
- [Standard Query Operators Overview](../../linq/standard-query-operators/index.md)
- [Conversion rules for Instance parameters and their impact](/archive/blogs/sreekarc/conversion-rules-for-instance-parameters-and-their-impact)
diff --git a/docs/framework/interop/marshalling-classes-structures-and-unions.md b/docs/framework/interop/marshalling-classes-structures-and-unions.md
index 1e732e3c9cb6f..edcf08b258b96 100644
--- a/docs/framework/interop/marshalling-classes-structures-and-unions.md
+++ b/docs/framework/interop/marshalling-classes-structures-and-unions.md
@@ -2,11 +2,11 @@
title: "Marshalling Classes, Structures, and Unions"
description: Review how to marshal classes, structures, and unions. View samples of marshalling classes, structures with nested structures, arrays of structures, and unions.
ms.date: "03/30/2017"
-dev_langs:
+dev_langs:
- "csharp"
- "vb"
- "cpp"
-helpviewer_keywords:
+helpviewer_keywords:
- "data marshalling, classes"
- "marshaling, unions"
- "marshaling, structures"
@@ -42,8 +42,8 @@ The following table lists marshalling options for classes, structures, and union
## Structures sample
-This sample demonstrates how to pass a structure that points to a second structure, pass a structure with an embedded structure, and pass a structure with an embedded array.
-
+This sample demonstrates how to pass a structure that points to a second structure, pass a structure with an embedded structure, and pass a structure with an embedded array.
+
The Structs sample uses the following unmanaged functions, shown with their original function declaration:
- **TestStructInStruct** exported from PinvokeLib.dll.
@@ -222,7 +222,7 @@ The `NativeMethods` class contains the prototypes for the `TestUnion` and `TestU
In some scenarios, `struct` and `union` layouts can differ depending on the targeted platform. For example, consider the [`STRRET`](/windows/win32/api/shtypes/ns-shtypes-strret) type when defined in a COM scenario:
-```c++
+```cpp
#include /* Defines the packing of the struct */
typedef struct _STRRET
{
diff --git a/docs/fundamentals/reflection/accessing-custom-attributes.md b/docs/fundamentals/reflection/accessing-custom-attributes.md
index 4db97c19a6490..20cbf5f901a4a 100644
--- a/docs/fundamentals/reflection/accessing-custom-attributes.md
+++ b/docs/fundamentals/reflection/accessing-custom-attributes.md
@@ -5,12 +5,10 @@ ms.date: 03/27/2024
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "custom attributes, accessibility"
- "attributes [.NET], accessing"
- "reflection, custom attributes"
-ms.assetid: 1d8e3398-00d8-47d5-a084-214f9859d3d7
---
# Access custom attributes
@@ -61,7 +59,6 @@ The custom attribute reflection model could leak instances of user-defined types
The following example demonstrates the basic way of using reflection to get access to custom attributes.
-[!code-cpp[CustomAttributeData#2](../../../samples/snippets/cpp/VS_Snippets_CLR/CustomAttributeData/CPP/source2.cpp#2)]
[!code-csharp[CustomAttributeData#2](../../../samples/snippets/csharp/VS_Snippets_CLR/CustomAttributeData/CS/source2.cs#2)]
[!code-vb[CustomAttributeData#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/CustomAttributeData/VB/source2.vb#2)]
diff --git a/docs/fundamentals/reflection/dynamically-loading-and-using-types.md b/docs/fundamentals/reflection/dynamically-loading-and-using-types.md
index c6dcb8d173c4c..64a91283bce27 100644
--- a/docs/fundamentals/reflection/dynamically-loading-and-using-types.md
+++ b/docs/fundamentals/reflection/dynamically-loading-and-using-types.md
@@ -5,14 +5,12 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "late binding, about late binding"
- "early binding"
- "dynamically loading and using types"
- "implicit late binding"
- "reflection, dynamically using types"
-ms.assetid: db985bec-5942-40ec-b13a-771ae98623dc
---
# Dynamically load and use types
@@ -44,7 +42,6 @@ Using custom binding, you can load an assembly at run time, obtain information a
The following example demonstrates a simple custom binder that provides no argument type conversion. Code for `Simple_Type.dll` precedes the main example. Be sure to build `Simple_Type.dll` and then include a reference to it in the project at build time.
-[!code-cpp[Conceptual.Types.Dynamic#1](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.dynamic/cpp/source1.cpp#1)]
[!code-csharp[Conceptual.Types.Dynamic#1](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.dynamic/cs/source1.cs#1)]
[!code-vb[Conceptual.Types.Dynamic#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.dynamic/vb/source1.vb#1)]
@@ -54,7 +51,6 @@ Use to invoke a
The following example shows the three possible combinations of argument coercion (type conversion) and member selection. In Case 1, no argument coercion or member selection is needed. In Case 2, only member selection is needed. In Case 3, only argument coercion is needed.
-[!code-cpp[Conceptual.Types.Dynamic#2](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.dynamic/cpp/source2.cpp#2)]
[!code-csharp[Conceptual.Types.Dynamic#2](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.dynamic/cs/source2.cs#2)]
[!code-vb[Conceptual.Types.Dynamic#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.dynamic/vb/source2.vb#2)]
diff --git a/docs/fundamentals/reflection/get-type-member-information.md b/docs/fundamentals/reflection/get-type-member-information.md
index 2fd0e4f4cafee..b1c83e1c36eef 100644
--- a/docs/fundamentals/reflection/get-type-member-information.md
+++ b/docs/fundamentals/reflection/get-type-member-information.md
@@ -6,9 +6,7 @@ ms.topic: how-to
helpviewer_keywords:
- "reflection, obtaining member information"
- "types [.NET], obtaining member information from"
-ms.assetid: 348ae651-ccda-4f13-8eda-19e8337e9438
dev_langs:
- - "cpp"
- "csharp"
- "vb"
---
@@ -20,7 +18,6 @@ The namespace contains many methods for obtaining infor
The following example obtains type and member information by using reflection:
-[!code-cpp[Get type members](../../../samples/snippets/standard/reflection/memberinfo/gettypemembers.cpp)]
[!code-csharp[Get type members](../../../samples/snippets/standard/reflection/memberinfo/gettypemembers.cs)]
[!code-vb[Get type members](../../../samples/snippets/standard/reflection/memberinfo/gettypemembers.vb)]
diff --git a/docs/fundamentals/reflection/how-to-define-a-generic-type-with-reflection-emit.md b/docs/fundamentals/reflection/how-to-define-a-generic-type-with-reflection-emit.md
index 3b41e829dbe32..ab135521f8f2e 100644
--- a/docs/fundamentals/reflection/how-to-define-a-generic-type-with-reflection-emit.md
+++ b/docs/fundamentals/reflection/how-to-define-a-generic-type-with-reflection-emit.md
@@ -5,12 +5,10 @@ ms.date: 03/27/2024
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "generics [.NET], reflection emit"
- "generics [.NET], dynamic types"
- "reflection emit, generic types"
-ms.assetid: 07d5f01a-7b5b-40ea-9b15-f21561098fe4
---
# How to: Define a generic type with reflection emit
@@ -23,19 +21,16 @@ This article shows how to create a simple generic type with two type parameters,
1. Define a dynamic assembly named `GenericEmitExample1`. In this example, the assembly is executed and saved to disk, so is specified.
- [!code-cpp[EmitGenericType#2](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#2)]
[!code-csharp[EmitGenericType#2](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#2)]
[!code-vb[EmitGenericType#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#2)]
1. Define a dynamic module. An assembly is made up of executable modules. For a single-module assembly, the module name is the same as the assembly name, and the file name is the module name plus an extension.
- [!code-cpp[EmitGenericType#3](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#3)]
[!code-csharp[EmitGenericType#3](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#3)]
[!code-vb[EmitGenericType#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#3)]
1. Define a class. In this example, the class is named `Sample`.
- [!code-cpp[EmitGenericType#4](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#4)]
[!code-csharp[EmitGenericType#4](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#4)]
[!code-vb[EmitGenericType#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#4)]
@@ -43,31 +38,26 @@ This article shows how to create a simple generic type with two type parameters,
In the following code, `Sample` becomes a generic type with type parameters `TFirst` and `TSecond`. To make the code easier to read, each is placed in a variable with the same name as the type parameter.
- [!code-cpp[EmitGenericType#5](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#5)]
[!code-csharp[EmitGenericType#5](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#5)]
[!code-vb[EmitGenericType#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#5)]
1. Add special constraints to the type parameters. In this example, type parameter `TFirst` is constrained to types that have parameterless constructors, and to reference types.
- [!code-cpp[EmitGenericType#6](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#6)]
[!code-csharp[EmitGenericType#6](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#6)]
[!code-vb[EmitGenericType#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#6)]
1. Optionally add class and interface constraints to the type parameters. In this example, type parameter `TFirst` is constrained to types that derive from the base class represented by the object contained in the variable `baseType`, and that implement the interfaces whose types are contained in the variables `interfaceA` and `interfaceB`. See the code example for the declaration and assignment of these variables.
- [!code-cpp[EmitGenericType#7](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#7)]
[!code-csharp[EmitGenericType#7](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#7)]
[!code-vb[EmitGenericType#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#7)]
1. Define a field. In this example, the type of the field is specified by type parameter `TFirst`. derives from , so you can use generic type parameters anywhere a type can be used.
- [!code-cpp[EmitGenericType#21](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#21)]
[!code-csharp[EmitGenericType#21](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#21)]
[!code-vb[EmitGenericType#21](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#21)]
1. Define a method that uses the type parameters of the generic type. Note that such methods are not generic unless they have their own type parameter lists. The following code defines a `static` method (`Shared` in Visual Basic) that takes an array of `TFirst` and returns a `List` (`List(Of TFirst)` in Visual Basic) containing all the elements of the array. To define this method, it is necessary to create the type `List` by calling on the generic type definition, `List`. (The `T` is omitted when you use the `typeof` operator (`GetType` in Visual Basic) to get the generic type definition.) The parameter type is created by using the method.
- [!code-cpp[EmitGenericType#22](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#22)]
[!code-csharp[EmitGenericType#22](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#22)]
[!code-vb[EmitGenericType#22](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#22)]
@@ -82,25 +72,21 @@ This article shows how to create a simple generic type with two type parameters,
Now it is possible to get the constructor of `List` by calling on the generic type definition. To convert this constructor to the corresponding constructor of `List`, pass `List` and the constructor from `List` to the static method.
- [!code-cpp[EmitGenericType#23](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#23)]
[!code-csharp[EmitGenericType#23](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#23)]
[!code-vb[EmitGenericType#23](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#23)]
1. Create the type and save the file.
- [!code-cpp[EmitGenericType#8](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#8)]
[!code-csharp[EmitGenericType#8](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#8)]
[!code-vb[EmitGenericType#8](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#8)]
1. Invoke the method. `ExampleMethod` is not generic, but the type it belongs to is generic, so to get a that can be invoked, it's necessary to create a constructed type from the type definition for `Sample`. The constructed type uses the `Example` class, which satisfies the constraints on `TFirst` because it is a reference type and has a default parameterless constructor, and the `ExampleDerived` class which satisfies the constraints on `TSecond`. (The code for `ExampleDerived` can be found in the example code section.) These two types are passed to to create the constructed type. The is then obtained using the method.
- [!code-cpp[EmitGenericType#9](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#9)]
[!code-csharp[EmitGenericType#9](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#9)]
[!code-vb[EmitGenericType#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#9)]
1. The following code creates an array of `Example` objects, places that array in an array of type representing the arguments of the method to be invoked, and passes them to the method. The first argument of the method is a null reference because the method is `static`.
- [!code-cpp[EmitGenericType#10](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#10)]
[!code-csharp[EmitGenericType#10](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#10)]
[!code-vb[EmitGenericType#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#10)]
@@ -118,7 +104,6 @@ The program includes a method that lists information about a generic type, and a
The program saves the finished module to disk as `GenericEmitExample1.dll`, so you can open it with the [Ildasm.exe (IL Disassembler)](../../framework/tools/ildasm-exe-il-disassembler.md) and examine the CIL for the `Sample` class.
-[!code-cpp[EmitGenericType#1](../../../samples/snippets/cpp/VS_Snippets_CLR/EmitGenericType/CPP/source.cpp#1)]
[!code-csharp[EmitGenericType#1](../../../samples/snippets/csharp/VS_Snippets_CLR/EmitGenericType/CS/source.cs#1)]
[!code-vb[EmitGenericType#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/EmitGenericType/VB/source.vb#1)]
diff --git a/docs/fundamentals/reflection/how-to-define-and-execute-dynamic-methods.md b/docs/fundamentals/reflection/how-to-define-and-execute-dynamic-methods.md
index 7025750fcf7a7..39026225aa5ca 100644
--- a/docs/fundamentals/reflection/how-to-define-and-execute-dynamic-methods.md
+++ b/docs/fundamentals/reflection/how-to-define-and-execute-dynamic-methods.md
@@ -5,11 +5,9 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "reflection emit, dynamic methods"
- "dynamic methods"
-ms.assetid: 07d08a99-62c5-4254-bce2-2a75e55a18ab
---
# How to: Define and execute dynamic methods
@@ -17,13 +15,11 @@ The following procedures show how to define and execute a simple dynamic method
1. Declare a delegate type to execute the method. Consider using a generic delegate to minimize the number of delegate types you need to declare. The following code declares two delegate types that could be used for the `SquareIt` method, and one of them is generic.
- [!code-cpp[DynamicMethodHowTo#2](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#2)]
[!code-csharp[DynamicMethodHowTo#2](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#2)]
[!code-vb[DynamicMethodHowTo#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#2)]
1. Create an array that specifies the parameter types for the dynamic method. In this example, the only parameter is an `int` (`Integer` in Visual Basic), so the array has only one element.
- [!code-cpp[DynamicMethodHowTo#3](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#3)]
[!code-csharp[DynamicMethodHowTo#3](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#3)]
[!code-vb[DynamicMethodHowTo#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#3)]
@@ -34,7 +30,6 @@ The following procedures show how to define and execute a simple dynamic method
The type of the return value is specified as `long`. The method is associated with the module that contains the `Example` class, which contains the example code. Any loaded module could be specified. The dynamic method acts like a module-level `static` method (`Shared` in Visual Basic).
- [!code-cpp[DynamicMethodHowTo#4](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#4)]
[!code-csharp[DynamicMethodHowTo#4](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#4)]
[!code-vb[DynamicMethodHowTo#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#4)]
@@ -42,31 +37,26 @@ The following procedures show how to define and execute a simple dynamic method
The CIL in this example loads the argument, which is an `int`, onto the stack, converts it to a `long`, duplicates the `long`, and multiplies the two numbers. This leaves the squared result on the stack, and all the method has to do is return.
- [!code-cpp[DynamicMethodHowTo#5](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#5)]
[!code-csharp[DynamicMethodHowTo#5](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#5)]
[!code-vb[DynamicMethodHowTo#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#5)]
1. Create an instance of the delegate (declared in step 1) that represents the dynamic method by calling the method. Creating the delegate completes the method, and any further attempts to change the method — for example, adding more CIL — are ignored. The following code creates the delegate and invokes it, using a generic delegate.
- [!code-cpp[DynamicMethodHowTo#6](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#6)]
[!code-csharp[DynamicMethodHowTo#6](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#6)]
[!code-vb[DynamicMethodHowTo#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#6)]
1. Declare a delegate type to execute the method. Consider using a generic delegate to minimize the number of delegate types you need to declare. The following code declares a generic delegate type that can be used to execute any method with one parameter and a return value, or a method with two parameters and a return value if the delegate is bound to an object.
- [!code-cpp[DynamicMethodHowTo#12](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#12)]
[!code-csharp[DynamicMethodHowTo#12](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#12)]
[!code-vb[DynamicMethodHowTo#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#12)]
1. Create an array that specifies the parameter types for the dynamic method. If the delegate representing the method is to be bound to an object, the first parameter must match the type the delegate is bound to. In this example, there are two parameters, of type `Example` and type `int` (`Integer` in Visual Basic).
- [!code-cpp[DynamicMethodHowTo#13](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#13)]
[!code-csharp[DynamicMethodHowTo#13](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#13)]
[!code-vb[DynamicMethodHowTo#13](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#13)]
1. Create a . In this example the method has no name. The type of the return value is specified as `int` (`Integer` in Visual Basic). The method has access to the private and protected members of the `Example` class.
- [!code-cpp[DynamicMethodHowTo#14](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#14)]
[!code-csharp[DynamicMethodHowTo#14](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#14)]
[!code-vb[DynamicMethodHowTo#14](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#14)]
@@ -74,7 +64,6 @@ The following procedures show how to define and execute a simple dynamic method
The CIL in this example loads the first argument, which is an instance of the `Example` class, and uses it to load the value of a private instance field of type `int`. The second argument is loaded, and the two numbers are multiplied. If the result is larger than `int`, the value is truncated and the most significant bits are discarded. The method returns, with the return value on the stack.
- [!code-cpp[DynamicMethodHowTo#15](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#15)]
[!code-csharp[DynamicMethodHowTo#15](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#15)]
[!code-vb[DynamicMethodHowTo#15](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#15)]
@@ -87,7 +76,6 @@ The following procedures show how to define and execute a simple dynamic method
The delegate `OneParameter` is used because the first parameter of the method always receives the instance of `Example`. When the delegate is invoked, only the second parameter is required.
- [!code-cpp[DynamicMethodHowTo#16](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#16)]
[!code-csharp[DynamicMethodHowTo#16](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#16)]
[!code-vb[DynamicMethodHowTo#16](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#16)]
@@ -101,7 +89,6 @@ The second dynamic method has two parameters, of type `Example` and type `int` (
The code example defines delegates that can be used to execute the methods.
-[!code-cpp[DynamicMethodHowTo#1](../../../samples/snippets/cpp/VS_Snippets_CLR/DynamicMethodHowTo/cpp/source.cpp#1)]
[!code-csharp[DynamicMethodHowTo#1](../../../samples/snippets/csharp/VS_Snippets_CLR/DynamicMethodHowTo/cs/source.cs#1)]
[!code-vb[DynamicMethodHowTo#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/DynamicMethodHowTo/vb/source.vb#1)]
diff --git a/docs/fundamentals/reflection/how-to-hook-up-a-delegate-using-reflection.md b/docs/fundamentals/reflection/how-to-hook-up-a-delegate-using-reflection.md
index b796fddb8e5b0..0b4616478458d 100644
--- a/docs/fundamentals/reflection/how-to-hook-up-a-delegate-using-reflection.md
+++ b/docs/fundamentals/reflection/how-to-hook-up-a-delegate-using-reflection.md
@@ -5,12 +5,10 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "events [.NET], adding event handlers with reflection"
- "reflection, adding event-handler delegates"
- "delegates [.NET], adding event handlers with reflection"
-ms.assetid: 076ee62d-a964-449e-a447-c31b33518b81
---
# How to: Hook up a delegate using reflection
@@ -23,43 +21,36 @@ When you use reflection to load and run assemblies, you can't use language featu
1. Load an assembly that contains a type that raises events. Assemblies are usually loaded with the method. To keep this example simple, a derived form in the current assembly is used, so the method is used to load the current assembly.
- [!code-cpp[HookUpDelegate#3](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#3)]
[!code-csharp[HookUpDelegate#3](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#3)]
[!code-vb[HookUpDelegate#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#3)]
2. Get a object representing the type, and create an instance of the type. The method is used in the following code because the form has a parameterless constructor. There are several other overloads of the method that you can use if the type you are creating does not have a parameterless constructor. The new instance is stored as type to maintain the fiction that nothing is known about the assembly. (Reflection allows you to get the types in an assembly without knowing their names in advance.)
- [!code-cpp[HookUpDelegate#4](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#4)]
[!code-csharp[HookUpDelegate#4](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#4)]
[!code-vb[HookUpDelegate#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#4)]
3. Get an object representing the event, and use the property to get the type of delegate used to handle the event. In the following code, an for the event is obtained.
- [!code-cpp[HookUpDelegate#5](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#5)]
[!code-csharp[HookUpDelegate#5](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#5)]
[!code-vb[HookUpDelegate#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#5)]
4. Get a object representing the method that handles the event. The complete program code in the Example section later in this article contains a method that matches the signature of the delegate, which handles the event, but you can also generate dynamic methods at run time. For details, see the accompanying procedure, for generating an event handler at run time by using a dynamic method.
- [!code-cpp[HookUpDelegate#6](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#6)]
[!code-csharp[HookUpDelegate#6](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#6)]
[!code-vb[HookUpDelegate#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#6)]
5. Create an instance of the delegate, using the method. This method is static (`Shared` in Visual Basic), so the delegate type must be supplied. Using the overloads of that take a is recommended.
- [!code-cpp[HookUpDelegate#7](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#7)]
[!code-csharp[HookUpDelegate#7](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#7)]
[!code-vb[HookUpDelegate#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#7)]
6. Get the `add` accessor method and invoke it to hook up the event. All events have an `add` accessor and a `remove` accessor, which are hidden by the syntax of high-level languages. For example, C# uses the `+=` operator to hook up events, and Visual Basic uses the [AddHandler statement](../../visual-basic/language-reference/statements/addhandler-statement.md). The following code gets the `add` accessor of the event and invokes it late-bound, passing in the delegate instance. The arguments must be passed as an array.
- [!code-cpp[HookUpDelegate#8](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#8)]
[!code-csharp[HookUpDelegate#8](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#8)]
[!code-vb[HookUpDelegate#8](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#8)]
7. Test the event. The following code shows the form defined in the code example. Clicking the form invokes the event handler.
- [!code-cpp[HookUpDelegate#12](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#12)]
[!code-csharp[HookUpDelegate#12](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#12)]
[!code-vb[HookUpDelegate#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#12)]
@@ -69,25 +60,21 @@ When you use reflection to load and run assemblies, you can't use language featu
It is not necessary to name a , so the empty string can be used. In the following code, the last argument associates the dynamic method with the current type, giving the delegate access to all the public and private members of the `Example` class.
- [!code-cpp[HookUpDelegate#9](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#9)]
[!code-csharp[HookUpDelegate#9](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#9)]
[!code-vb[HookUpDelegate#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#9)]
2. Generate a method body. This method loads a string, calls the overload of the method that takes a string, pops the return value off the stack (because the handler has no return type), and returns. To learn more about emitting dynamic methods, see [How to: Define and Execute Dynamic Methods](how-to-define-and-execute-dynamic-methods.md).
- [!code-cpp[HookUpDelegate#10](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#10)]
[!code-csharp[HookUpDelegate#10](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#10)]
[!code-vb[HookUpDelegate#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#10)]
3. Complete the dynamic method by calling its method. Use the `add` accessor to add the delegate to the invocation list for the event.
- [!code-cpp[HookUpDelegate#11](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#11)]
[!code-csharp[HookUpDelegate#11](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#11)]
[!code-vb[HookUpDelegate#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#11)]
4. Test the event. The following code loads the form defined in the code example. Clicking the form invokes both the predefined event handler and the emitted event handler.
- [!code-cpp[HookUpDelegate#12](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#12)]
[!code-csharp[HookUpDelegate#12](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#12)]
[!code-vb[HookUpDelegate#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#12)]
@@ -95,7 +82,6 @@ When you use reflection to load and run assemblies, you can't use language featu
The following code example shows how to hook up an existing method to an event using reflection, and also how to use the class to emit a method at run time and hook it up to an event.
-[!code-cpp[HookUpDelegate#1](../../../samples/snippets/cpp/VS_Snippets_CLR/HookUpDelegate/cpp/source.cpp#1)]
[!code-csharp[HookUpDelegate#1](../../../samples/snippets/csharp/VS_Snippets_CLR/HookUpDelegate/cs/source.cs#1)]
[!code-vb[HookUpDelegate#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/HookUpDelegate/vb/source.vb#1)]
diff --git a/docs/fundamentals/reflection/reflection-and-generic-types.md b/docs/fundamentals/reflection/reflection-and-generic-types.md
index c7f30a2223851..af39e27832a44 100644
--- a/docs/fundamentals/reflection/reflection-and-generic-types.md
+++ b/docs/fundamentals/reflection/reflection-and-generic-types.md
@@ -5,7 +5,6 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "generics [.NET], reflection emit"
- "reflection emit, generic types"
@@ -16,7 +15,6 @@ helpviewer_keywords:
- "type information, viewing"
- "types, generic"
- "type parameters"
-ms.assetid: f7180fc5-dd41-42d4-8a8e-1b34288e06de
---
# Reflection and generic types
@@ -88,11 +86,6 @@ Class D(Of V, W)
End Class
```
-```cpp
-generic ref class B {};
-generic ref class D : B {};
-```
-
If you obtain a object representing `D` and use the property to obtain its base type, the resulting `type B` is open, but it's not a generic type definition.
### Source of a generic parameter
diff --git a/docs/fundamentals/reflection/viewing-type-information.md b/docs/fundamentals/reflection/viewing-type-information.md
index 20ea9422180ba..e28cb3076f91d 100644
--- a/docs/fundamentals/reflection/viewing-type-information.md
+++ b/docs/fundamentals/reflection/viewing-type-information.md
@@ -5,13 +5,11 @@ ms.date: 03/27/2024
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "types, viewing type information"
- "Type object"
- "viewing type information"
- "reflection, viewing type information"
-ms.assetid: 7e7303a9-4064-4738-b4e7-b75974ed70d2
---
# View type information
@@ -24,13 +22,11 @@ Use or
The following example shows the syntax necessary to get the object and module for an assembly.
-[!code-cpp[Conceptual.Types.ViewInfo#6](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.viewinfo/cpp/source5.cpp#6)]
[!code-csharp[Conceptual.Types.ViewInfo#6](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.viewinfo/cs/source5.cs#6)]
[!code-vb[Conceptual.Types.ViewInfo#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.viewinfo/vb/source5.vb#6)]
The following example demonstrates getting `Type` objects from a loaded assembly.
-[!code-cpp[Conceptual.Types.ViewInfo#7](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.viewinfo/cpp/source5.cpp#7)]
[!code-csharp[Conceptual.Types.ViewInfo#7](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.viewinfo/cs/source5.cs#7)]
[!code-vb[Conceptual.Types.ViewInfo#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.viewinfo/vb/source5.vb#7)]
@@ -44,7 +40,6 @@ If you have a `Type`, you can use the class.
-[!code-cpp[Conceptual.Types.ViewInfo#1](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.viewinfo/cpp/source1.cpp#1)]
[!code-csharp[Conceptual.Types.ViewInfo#1](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.viewinfo/cs/source1.cs#1)]
[!code-vb[Conceptual.Types.ViewInfo#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.viewinfo/vb/source1.vb#1)]
@@ -54,18 +49,15 @@ Obtain information about the type's methods, properties, events, and fields usin
The following example uses `MemberInfo` to list the number of members in the `System.IO.File` class and uses the property to determine the visibility of the class.
-[!code-cpp[Conceptual.Types.ViewInfo#2](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.viewinfo/cpp/source2.cpp#2)]
[!code-csharp[Conceptual.Types.ViewInfo#2](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.viewinfo/cs/source2.cs#2)]
[!code-vb[Conceptual.Types.ViewInfo#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.viewinfo/vb/source2.vb#2)]
The following example investigates the type of the specified member. It performs reflection on a member of the `MemberInfo` class, and lists its type.
-[!code-cpp[Conceptual.Types.ViewInfo#3](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.viewinfo/cpp/source3.cpp#3)]
[!code-csharp[Conceptual.Types.ViewInfo#3](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.viewinfo/cs/source3.cs#3)]
[!code-vb[Conceptual.Types.ViewInfo#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.viewinfo/vb/source3.vb#3)]
The following example uses all the Reflection `*Info` classes along with to list all the members (constructors, fields, properties, events, and methods) of the specified class, dividing the members into static and instance categories.
-[!code-cpp[Conceptual.Types.ViewInfo#4](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.types.viewinfo/cpp/source4.cpp#4)]
[!code-csharp[Conceptual.Types.ViewInfo#4](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.types.viewinfo/cs/source4.cs#4)]
[!code-vb[Conceptual.Types.ViewInfo#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.types.viewinfo/vb/source4.vb#4)]
diff --git a/docs/navigate/devops-testing/toc.yml b/docs/navigate/devops-testing/toc.yml
index 03a0fff1e4bb1..96cf78d381915 100644
--- a/docs/navigate/devops-testing/toc.yml
+++ b/docs/navigate/devops-testing/toc.yml
@@ -207,6 +207,10 @@ items:
href: ../../core/testing/mstest-analyzers/mstest0040.md
- name: MSTEST0041
href: ../../core/testing/mstest-analyzers/mstest0041.md
+ - name: MSTEST0042
+ href: ../../core/testing/mstest-analyzers/mstest0042.md
+ - name: MSTEST0043
+ href: ../../core/testing/mstest-analyzers/mstest0043.md
- name: Test platforms
items:
- name: Microsoft.Testing.Platform
diff --git a/docs/standard/assembly/find-fully-qualified-name.md b/docs/standard/assembly/find-fully-qualified-name.md
index c7c1b7a85ebf1..4b1ac4b558f1b 100644
--- a/docs/standard/assembly/find-fully-qualified-name.md
+++ b/docs/standard/assembly/find-fully-qualified-name.md
@@ -10,7 +10,6 @@ ms.topic: how-to
dev_langs:
- "csharp"
- "vb"
- - "cpp"
---
# How to: Find an assembly's fully qualified name
@@ -59,31 +58,6 @@ For more information about setting assembly attributes such as version, culture,
The following example shows how to display the fully qualified name of an assembly containing a specified class to the console. It uses the property to retrieve a reference to an assembly from a type that's defined in that assembly.
-```cpp
-#using
-#using
-
-using namespace System;
-using namespace System::Reflection;
-
-ref class asmname
-{
-public:
- static void Main()
- {
- Type^ t = System::Data::DataSet::typeid;
- String^ s = t->Assembly->FullName->ToString();
- Console::WriteLine("The fully qualified assembly name " +
- "containing the specified class is {0}.", s);
- }
-};
-
-int main()
-{
- asmname::Main();
-}
-```
-
```csharp
using System;
using System.Reflection;
diff --git a/docs/standard/assembly/view-contents.md b/docs/standard/assembly/view-contents.md
index ad4b040cdb025..07dedf77feb79 100644
--- a/docs/standard/assembly/view-contents.md
+++ b/docs/standard/assembly/view-contents.md
@@ -14,7 +14,6 @@ ms.topic: how-to
dev_langs:
- "csharp"
- "vb"
- - "cpp"
---
# How to: View assembly contents
@@ -32,24 +31,6 @@ To view assembly manifest information, double-click the **Manifest** icon in the
The following example starts with a basic "Hello World" program. After compiling the program, use *Ildasm.exe* to disassemble the *Hello.exe* assembly and view the assembly manifest.
-```cpp
-using namespace System;
-
-class MainApp
-{
-public:
- static void Main()
- {
- Console::WriteLine("Hello World using C++/CLI!");
- }
-};
-
-int main()
-{
- MainApp::Main();
-}
-```
-
```csharp
using System;
diff --git a/docs/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously.md b/docs/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously.md
index 18587a893e8f2..3fe054610315a 100644
--- a/docs/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously.md
+++ b/docs/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously.md
@@ -5,7 +5,6 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "asynchronous programming, delegates"
- "asynchronous delegates"
@@ -19,7 +18,6 @@ helpviewer_keywords:
- "synchronous calling in asynchronous manner"
- "waiting for asynchronous calls"
- "status information [.NET], asynchronous operations"
-ms.assetid: 41972034-92ed-450a-9664-ab93fcc6f1fb
---
# Calling Synchronous Methods Asynchronously
@@ -54,7 +52,6 @@ The code examples in this topic demonstrate four common ways to use `BeginInvoke
The following code example shows the definition of `TestMethod` and the delegate named `AsyncMethodCaller` that can be used to call `TestMethod` asynchronously. To compile the code examples, you must include the definitions for `TestMethod` and the `AsyncMethodCaller` delegate.
- [!code-cpp[AsyncDelegateExamples#1](../../../samples/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/TestMethod.cpp#1)]
[!code-csharp[AsyncDelegateExamples#1](../../../samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/TestMethod.cs#1)]
[!code-vb[AsyncDelegateExamples#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb#1)]
@@ -65,7 +62,6 @@ The code examples in this topic demonstrate four common ways to use `BeginInvoke
> [!IMPORTANT]
> Because `EndInvoke` might block, you should never call it from threads that service the user interface.
- [!code-cpp[AsyncDelegateExamples#2](../../../samples/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/EndInvoke.cpp#2)]
[!code-csharp[AsyncDelegateExamples#2](../../../samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/EndInvoke.cs#2)]
[!code-vb[AsyncDelegateExamples#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/EndInvoke.vb#2)]
@@ -78,7 +74,6 @@ The code examples in this topic demonstrate four common ways to use `BeginInvoke
> [!NOTE]
> The wait handle is not closed automatically when you call `EndInvoke`. If you release all references to the wait handle, system resources are freed when garbage collection reclaims the wait handle. To free the system resources as soon as you are finished using the wait handle, dispose of it by calling the method. Garbage collection works more efficiently when disposable objects are explicitly disposed.
- [!code-cpp[AsyncDelegateExamples#3](../../../samples/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/waithandle.cpp#3)]
[!code-csharp[AsyncDelegateExamples#3](../../../samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/waithandle.cs#3)]
[!code-vb[AsyncDelegateExamples#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/WaitHandle.vb#3)]
@@ -86,7 +81,6 @@ The code examples in this topic demonstrate four common ways to use `BeginInvoke
You can use the property of the returned by `BeginInvoke` to discover when the asynchronous call completes. You might do this when making the asynchronous call from a thread that services the user interface. Polling for completion allows the calling thread to continue executing while the asynchronous call executes on a thread.
- [!code-cpp[AsyncDelegateExamples#4](../../../samples/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/polling.cpp#4)]
[!code-csharp[AsyncDelegateExamples#4](../../../samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/polling.cs#4)]
[!code-vb[AsyncDelegateExamples#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/polling.vb#4)]
@@ -104,7 +98,6 @@ The code examples in this topic demonstrate four common ways to use `BeginInvoke
- The callback is made on a thread. threads are background threads, which do not keep the application running if the main thread ends, so the main thread of the example has to sleep long enough for the callback to finish.
- [!code-cpp[AsyncDelegateExamples#5](../../../samples/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/callback.cpp#5)]
[!code-csharp[AsyncDelegateExamples#5](../../../samples/snippets/csharp/VS_Snippets_CLR/AsyncDelegateExamples/CS/callback.cs#5)]
[!code-vb[AsyncDelegateExamples#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/callback.vb#5)]
diff --git a/docs/standard/attributes/applying-attributes.md b/docs/standard/attributes/applying-attributes.md
index 398d8a18511da..e3567ff3dd90d 100644
--- a/docs/standard/attributes/applying-attributes.md
+++ b/docs/standard/attributes/applying-attributes.md
@@ -5,7 +5,6 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "assemblies [.NET], attributes"
- "attributes [.NET], applying"
@@ -31,17 +30,15 @@ Use the following process to apply an attribute to an element of your code.
## Apply an attribute to a method
- The following code example shows how to use **System.ObsoleteAttribute**, which marks code as obsolete. The string `"Will be removed in next version"` is passed to the attribute. This attribute causes a compiler warning that displays the passed string when code that the attribute describes is called.
+ The following code example shows how to use , which marks code as obsolete. The string `"Will be removed in next version"` is passed to the attribute. This attribute causes a compiler warning that displays the passed string when code that the attribute describes is called.
- [!code-cpp[Conceptual.Attributes.Usage#3](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source1.cpp#3)]
[!code-csharp[Conceptual.Attributes.Usage#3](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source1.cs#3)]
[!code-vb[Conceptual.Attributes.Usage#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source1.vb#3)]
## Apply attributes at the assembly level
- If you want to apply an attribute at the assembly level, use the `assembly` (`Assembly` in Visual Basic) keyword. The following code shows the **AssemblyTitleAttribute** applied at the assembly level.
+ If you want to apply an attribute at the assembly level, use the `assembly` (`Assembly` in Visual Basic) keyword. The following code shows the applied at the assembly level.
- [!code-cpp[Conceptual.Attributes.Usage#2](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source1.cpp#2)]
[!code-csharp[Conceptual.Attributes.Usage#2](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source1.cs#2)]
[!code-vb[Conceptual.Attributes.Usage#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source1.vb#2)]
diff --git a/docs/standard/attributes/retrieving-information-stored-in-attributes.md b/docs/standard/attributes/retrieving-information-stored-in-attributes.md
index f178f234fbb17..aaf3ad3038bc2 100644
--- a/docs/standard/attributes/retrieving-information-stored-in-attributes.md
+++ b/docs/standard/attributes/retrieving-information-stored-in-attributes.md
@@ -3,11 +3,10 @@ title: "Retrieving Information Stored in Attributes"
description: Learn to retrieve information stored in attributes, including for an attribute instance, multiple instances for the same scope, multiple instances for different scopes, and attributes applied to class members.
ms.date: "08/05/2022"
ms.custom: devdivchpfy22
-dev_langs:
+dev_langs:
- "csharp"
- "vb"
- - "cpp"
-helpviewer_keywords:
+helpviewer_keywords:
- "retrieving attributes"
- "multiple attribute instances"
- "attributes [.NET], retrieving"
@@ -15,76 +14,73 @@ ms.topic: how-to
---
# Retrieving Information Stored in Attributes
-Retrieving a custom attribute is a simple process. First, declare an instance of the attribute you want to retrieve. Then, use the method to initialize the new attribute to the value of the attribute you want to retrieve. Once the new attribute is initialized, you can use its properties to get the values.
-
+Retrieving a custom attribute is a simple process. First, declare an instance of the attribute you want to retrieve. Then, use the method to initialize the new attribute to the value of the attribute you want to retrieve. Once the new attribute is initialized, you can use its properties to get the values.
+
> [!IMPORTANT]
-> This article describes how to retrieve attributes for code loaded into the execution context. To retrieve attributes for code loaded into the reflection-only context, you must use the class, as shown in [How to: Load Assemblies into the Reflection-Only Context](../../framework/reflection-and-codedom/how-to-load-assemblies-into-the-reflection-only-context.md).
-
- This section describes the following ways to retrieve attributes:
-
-- [Retrieving a single instance of an attribute](#cpconretrievingsingleinstanceofattribute)
-
-- [Retrieving multiple instances of an attribute applied to the same scope](#cpconretrievingmultipleinstancesofattributeappliedtosamescope)
-
-- [Retrieving multiple instances of an attribute applied to different scopes](#cpconretrievingmultipleinstancesofattributeappliedtodifferentscopes)
-
+> This article describes how to retrieve attributes for code loaded into the execution context. To retrieve attributes for code loaded into the reflection-only context, you must use the class, as shown in [How to: Load Assemblies into the Reflection-Only Context](../../framework/reflection-and-codedom/how-to-load-assemblies-into-the-reflection-only-context.md).
+
+ This section describes the following ways to retrieve attributes:
+
+- [Retrieving a single instance of an attribute](#cpconretrievingsingleinstanceofattribute)
+
+- [Retrieving multiple instances of an attribute applied to the same scope](#cpconretrievingmultipleinstancesofattributeappliedtosamescope)
+
+- [Retrieving multiple instances of an attribute applied to different scopes](#cpconretrievingmultipleinstancesofattributeappliedtodifferentscopes)
+
-## Retrieving a Single Instance of an Attribute
+## Retrieving a Single Instance of an Attribute
+
+ In the following example, the `DeveloperAttribute` (described in the previous section) is applied to the `MainApp` class on the class level. The `GetAttribute` method uses `GetCustomAttribute` to retrieve the values stored in `DeveloperAttribute` on the class level before displaying them to the console.
- In the following example, the `DeveloperAttribute` (described in the previous section) is applied to the `MainApp` class on the class level. The `GetAttribute` method uses `GetCustomAttribute` to retrieve the values stored in `DeveloperAttribute` on the class level before displaying them to the console.
-
- [!code-cpp[Conceptual.Attributes.Usage#18](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source3.cpp#18)]
[!code-csharp[Conceptual.Attributes.Usage#18](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source3.cs#18)]
- [!code-vb[Conceptual.Attributes.Usage#18](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source3.vb#18)]
-
+ [!code-vb[Conceptual.Attributes.Usage#18](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source3.vb#18)]
+
The execution of the preceding program displays the following text:
-
-```console
-The Name Attribute is: Joan Smith.
-The Level Attribute is: 42.
-The Reviewed Attribute is: True.
-```
-
+
+```console
+The Name Attribute is: Joan Smith.
+The Level Attribute is: 42.
+The Reviewed Attribute is: True.
+```
+
If the attribute isn't found, the `GetCustomAttribute` method initializes `MyAttribute` to a null value. This example checks `MyAttribute` for such an instance and notifies the user if the attribute isn't found. If `DeveloperAttribute` isn't found in the class scope, the console displays the following message:
-
-```console
+
+```console
The attribute was not found.
-```
-
- The preceding example assumes that the attribute definition is in the current namespace. Remember to import the namespace in which the attribute definition resides if it isn't in the current namespace.
-
+```
+
+ The preceding example assumes that the attribute definition is in the current namespace. Remember to import the namespace in which the attribute definition resides if it isn't in the current namespace.
+
-## Retrieving Multiple Instances of an Attribute Applied to the Same Scope
+## Retrieving Multiple Instances of an Attribute Applied to the Same Scope
+
+ In the preceding example, the class to inspect and the specific attribute to find are passed to the method. That code works well if only one instance of an attribute is applied on the class level. However, if multiple instances of an attribute are applied on the same class level, the `GetCustomAttribute` method doesn't retrieve all the information. In cases where multiple instances of the same attribute are applied to the same scope, you can use method to place all instances of an attribute into an array. For example, if two instances of `DeveloperAttribute` are applied on the class level of the same class, the `GetAttribute` method can be modified to display the information found in both attributes. Remember, to apply multiple attributes on the same level. The attribute must be defined with the `AllowMultiple` property set to `true` in the class.
+
+ The following code example shows how to use the `GetCustomAttributes` method to create an array that references all instances of `DeveloperAttribute` in any given class. The code then outputs the values of all the attributes to the console.
- In the preceding example, the class to inspect and the specific attribute to find are passed to the method. That code works well if only one instance of an attribute is applied on the class level. However, if multiple instances of an attribute are applied on the same class level, the `GetCustomAttribute` method doesn't retrieve all the information. In cases where multiple instances of the same attribute are applied to the same scope, you can use method to place all instances of an attribute into an array. For example, if two instances of `DeveloperAttribute` are applied on the class level of the same class, the `GetAttribute` method can be modified to display the information found in both attributes. Remember, to apply multiple attributes on the same level. The attribute must be defined with the `AllowMultiple` property set to `true` in the class.
-
- The following code example shows how to use the `GetCustomAttributes` method to create an array that references all instances of `DeveloperAttribute` in any given class. The code then outputs the values of all the attributes to the console.
-
- [!code-cpp[Conceptual.Attributes.Usage#19](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source3.cpp#19)]
[!code-csharp[Conceptual.Attributes.Usage#19](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source3.cs#19)]
- [!code-vb[Conceptual.Attributes.Usage#19](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source3.vb#19)]
-
- If no attributes are found, this code alerts the user. Otherwise, the information contained in both instances of `DeveloperAttribute` is displayed.
-
+ [!code-vb[Conceptual.Attributes.Usage#19](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source3.vb#19)]
+
+ If no attributes are found, this code alerts the user. Otherwise, the information contained in both instances of `DeveloperAttribute` is displayed.
+
-## Retrieving Multiple Instances of an Attribute Applied to Different Scopes
+## Retrieving Multiple Instances of an Attribute Applied to Different Scopes
+
+ The and methods don't search an entire class and return all instances of an attribute in that class. Rather, they search only one specified method or member at a time. If you have a class with the same attribute applied to every member and you want to retrieve the values in all the attributes applied to those members, you must supply every method or member individually to `GetCustomAttributes` and `GetCustomAttribute`.
- The and methods don't search an entire class and return all instances of an attribute in that class. Rather, they search only one specified method or member at a time. If you have a class with the same attribute applied to every member and you want to retrieve the values in all the attributes applied to those members, you must supply every method or member individually to `GetCustomAttributes` and `GetCustomAttribute`.
-
The following code example takes a class as a parameter and searches for the `DeveloperAttribute` (defined previously) on the class level and on every individual method of that class:
-
- [!code-cpp[Conceptual.Attributes.Usage#20](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source3.cpp#20)]
+
[!code-csharp[Conceptual.Attributes.Usage#20](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source3.cs#20)]
- [!code-vb[Conceptual.Attributes.Usage#20](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source3.vb#20)]
-
- If no instances of the `DeveloperAttribute` are found on the method level or class level, the `GetAttribute` method notifies the user that no attributes were found and displays the name of the method or class that doesn't contain the attribute. If an attribute is found, the console displays the `Name`, `Level`, and `Reviewed` fields.
-
+ [!code-vb[Conceptual.Attributes.Usage#20](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source3.vb#20)]
+
+ If no instances of the `DeveloperAttribute` are found on the method level or class level, the `GetAttribute` method notifies the user that no attributes were found and displays the name of the method or class that doesn't contain the attribute. If an attribute is found, the console displays the `Name`, `Level`, and `Reviewed` fields.
+
You can use the members of the class to get the individual methods and members in the passed class. This example first queries the `Type` object to get attribute information for the class level. Next, it uses to place instances of all methods into an array of objects to retrieve attribute information for the method level. You can also use the method to check for attributes on the property level or to check for attributes on the constructor level.
-## Retrieving Attributes from Class Members
+## Retrieving Attributes from Class Members
In addition to retrieving attributes at the class level, attributes can also be applied to individual members such as methods, properties, and fields. The `GetCustomAttribute` and `GetCustomAttributes` methods can be used to retrieve these attributes.
@@ -93,7 +89,7 @@ In addition to retrieving attributes at the class level, attributes can also be
The following example demonstrates how to retrieve an attribute applied to a method:
[!code-csharp[Conceptual.Attributes.Usage#21](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source4.cs#21)]
-
+
## See also
-
diff --git a/docs/standard/attributes/writing-custom-attributes.md b/docs/standard/attributes/writing-custom-attributes.md
index feff372cd49df..d0d1545b77e04 100644
--- a/docs/standard/attributes/writing-custom-attributes.md
+++ b/docs/standard/attributes/writing-custom-attributes.md
@@ -3,11 +3,10 @@ title: "Writing Custom Attributes"
description: Design your own custom attributes in .NET. Custom attributes are essentially classes derived directly or indirectly from System.Attribute.
ms.date: "08/05/2022"
ms.custom: devdivchpfy22
-dev_langs:
+dev_langs:
- "csharp"
- "vb"
- - "cpp"
-helpviewer_keywords:
+helpviewer_keywords:
- "multiple attribute instances"
- "AttributeTargets enumeration"
- "attributes [.NET], custom"
@@ -16,143 +15,129 @@ helpviewer_keywords:
- "AttributeUsageAttribute class, custom attributes"
- "Inherited property"
- "attribute classes, declaring"
-ms.assetid: 97216f69-bde8-49fd-ac40-f18c500ef5dc
---
# Write custom attributes
-To design custom attributes, you don't need to learn many new concepts. If you're familiar with object-oriented programming and know how to design classes, you already have most of the knowledge needed. Custom attributes are traditional classes that derive directly or indirectly from the class. Just like traditional classes, custom attributes contain methods that store and retrieve data.
-
- The primary steps to properly design custom attribute classes are as follows:
-
-- [Applying the AttributeUsageAttribute](#applying-the-attributeusageattribute)
-
-- [Declaring the attribute class](#declaring-the-attribute-class)
-
-- [Declaring constructors](#declaring-constructors)
-
-- [Declaring properties](#declaring-properties)
-
+To design custom attributes, you don't need to learn many new concepts. If you're familiar with object-oriented programming and know how to design classes, you already have most of the knowledge needed. Custom attributes are traditional classes that derive directly or indirectly from the class. Just like traditional classes, custom attributes contain methods that store and retrieve data.
+
+ The primary steps to properly design custom attribute classes are as follows:
+
+- [Applying the AttributeUsageAttribute](#applying-the-attributeusageattribute)
+
+- [Declaring the attribute class](#declaring-the-attribute-class)
+
+- [Declaring constructors](#declaring-constructors)
+
+- [Declaring properties](#declaring-properties)
+
This section describes each of these steps and concludes with a [custom attribute example](#custom-attribute-example).
-
-## Applying the AttributeUsageAttribute
- A custom attribute declaration begins with the attribute, which defines some of the key characteristics of your attribute class. For example, you can specify whether your attribute can be inherited by other classes or which elements the attribute can be applied to. The following code fragment demonstrates how to use the :
-
- [!code-cpp[Conceptual.Attributes.Usage#5](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#5)]
+## Applying the AttributeUsageAttribute
+
+ A custom attribute declaration begins with the attribute, which defines some of the key characteristics of your attribute class. For example, you can specify whether your attribute can be inherited by other classes or which elements the attribute can be applied to. The following code fragment demonstrates how to use the :
+
[!code-csharp[Conceptual.Attributes.Usage#5](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#5)]
- [!code-vb[Conceptual.Attributes.Usage#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#5)]
-
- The has three members that are important for the creation of custom attributes: [AttributeTargets](#attributetargets-member), [Inherited](#inherited-property), and [AllowMultiple](#allowmultiple-property).
-
-### AttributeTargets Member
-
- In the preceding example, is specified, indicating that this attribute can be applied to all program elements. Alternatively, you can specify , indicating that your attribute can be applied only to a class, or , indicating that your attribute can be applied only to a method. All program elements can be marked for description by a custom attribute in this manner.
-
+ [!code-vb[Conceptual.Attributes.Usage#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#5)]
+
+ The has three members that are important for the creation of custom attributes: [AttributeTargets](#attributetargets-member), [Inherited](#inherited-property), and [AllowMultiple](#allowmultiple-property).
+
+### AttributeTargets Member
+
+ In the preceding example, is specified, indicating that this attribute can be applied to all program elements. Alternatively, you can specify , indicating that your attribute can be applied only to a class, or , indicating that your attribute can be applied only to a method. All program elements can be marked for description by a custom attribute in this manner.
+
You can also pass multiple values. The following code fragment specifies that a custom attribute can be applied to any class or method:
-
- [!code-cpp[Conceptual.Attributes.Usage#6](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#6)]
+
[!code-csharp[Conceptual.Attributes.Usage#6](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#6)]
- [!code-vb[Conceptual.Attributes.Usage#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#6)]
-
-### Inherited Property
+ [!code-vb[Conceptual.Attributes.Usage#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#6)]
+
+### Inherited Property
+
+ The property indicates whether your attribute can be inherited by classes that are derived from the classes to which your attribute is applied. This property takes either a `true` (the default) or `false` flag. In the following example, `MyAttribute` has a default value of `true`, while `YourAttribute` has an value of `false`:
- The property indicates whether your attribute can be inherited by classes that are derived from the classes to which your attribute is applied. This property takes either a `true` (the default) or `false` flag. In the following example, `MyAttribute` has a default value of `true`, while `YourAttribute` has an value of `false`:
-
- [!code-cpp[Conceptual.Attributes.Usage#7](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#7)]
[!code-csharp[Conceptual.Attributes.Usage#7](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#7)]
- [!code-vb[Conceptual.Attributes.Usage#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#7)]
-
+ [!code-vb[Conceptual.Attributes.Usage#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#7)]
+
The two attributes are then applied to a method in the base class `MyClass`:
-
- [!code-cpp[Conceptual.Attributes.Usage#9](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#9)]
+
[!code-csharp[Conceptual.Attributes.Usage#9](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#9)]
- [!code-vb[Conceptual.Attributes.Usage#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#9)]
-
+ [!code-vb[Conceptual.Attributes.Usage#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#9)]
+
Finally, the class `YourClass` is inherited from the base class `MyClass`. The method `MyMethod` shows `MyAttribute` but not `YourAttribute`:
-
- [!code-cpp[Conceptual.Attributes.Usage#10](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#10)]
+
[!code-csharp[Conceptual.Attributes.Usage#10](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#10)]
- [!code-vb[Conceptual.Attributes.Usage#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#10)]
-
-### AllowMultiple Property
+ [!code-vb[Conceptual.Attributes.Usage#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#10)]
+
+### AllowMultiple Property
+
+ The property indicates whether multiple instances of your attribute can exist on an element. If set to `true`, multiple instances are allowed. If set to `false` (the default), only one instance is allowed.
- The property indicates whether multiple instances of your attribute can exist on an element. If set to `true`, multiple instances are allowed. If set to `false` (the default), only one instance is allowed.
-
In the following example, `MyAttribute` has a default value of `false`, while `YourAttribute` has a value of `true`:
-
- [!code-cpp[Conceptual.Attributes.Usage#11](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#11)]
+
[!code-csharp[Conceptual.Attributes.Usage#11](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#11)]
- [!code-vb[Conceptual.Attributes.Usage#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#11)]
-
+ [!code-vb[Conceptual.Attributes.Usage#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#11)]
+
When multiple instances of these attributes are applied, `MyAttribute` produces a compiler error. The following code example shows the valid use of `YourAttribute` and the invalid use of `MyAttribute`:
-
- [!code-cpp[Conceptual.Attributes.Usage#13](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#13)]
+
[!code-csharp[Conceptual.Attributes.Usage#13](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#13)]
- [!code-vb[Conceptual.Attributes.Usage#13](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#13)]
-
- If both the property and the property are set to `true`, a class that's inherited from another class can inherit an attribute and have another instance of the same attribute applied in the same child class. If is set to `false`, the values of any attributes in the parent class will be overwritten by new instances of the same attribute in the child class.
-
-## Declaring the Attribute Class
+ [!code-vb[Conceptual.Attributes.Usage#13](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#13)]
+
+ If both the property and the property are set to `true`, a class that's inherited from another class can inherit an attribute and have another instance of the same attribute applied in the same child class. If is set to `false`, the values of any attributes in the parent class will be overwritten by new instances of the same attribute in the child class.
+
+## Declaring the Attribute Class
After you apply the , start defining the specifics of your attribute. The declaration of an attribute class looks similar to the declaration of a traditional class, as demonstrated by the following code:
-
- [!code-cpp[Conceptual.Attributes.Usage#14](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#14)]
+
[!code-csharp[Conceptual.Attributes.Usage#14](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#14)]
- [!code-vb[Conceptual.Attributes.Usage#14](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#14)]
-
- This attribute definition demonstrates the following points:
-
-- Attribute classes must be declared as public classes.
-
-- By convention, the name of the attribute class ends with the word **Attribute**. While not required, this convention is recommended for readability. When the attribute is applied, the inclusion of the word Attribute is optional.
-
-- All attribute classes must inherit directly or indirectly from the class.
-
-- In Microsoft Visual Basic, all custom attribute classes must have the attribute.
-
-## Declaring Constructors
+ [!code-vb[Conceptual.Attributes.Usage#14](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#14)]
+
+ This attribute definition demonstrates the following points:
+
+- Attribute classes must be declared as public classes.
+
+- By convention, the name of the attribute class ends with the word **Attribute**. While not required, this convention is recommended for readability. When the attribute is applied, the inclusion of the word Attribute is optional.
+
+- All attribute classes must inherit directly or indirectly from the class.
+
+- In Microsoft Visual Basic, all custom attribute classes must have the attribute.
+
+## Declaring Constructors
Just like traditional classes, attributes are initialized with constructors. The following code fragment illustrates a typical attribute constructor. This public constructor takes a parameter and sets a member variable equal to its value.
-
- [!code-cpp[Conceptual.Attributes.Usage#15](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#15)]
+
[!code-csharp[Conceptual.Attributes.Usage#15](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#15)]
- [!code-vb[Conceptual.Attributes.Usage#15](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#15)]
-
+ [!code-vb[Conceptual.Attributes.Usage#15](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#15)]
+
You can overload the constructor to accommodate different combinations of values. If you also define a [property](/previous-versions/visualstudio/visual-studio-2013/65zdfbdt(v=vs.120)) for your custom attribute class, you can use a combination of named and positional parameters when initializing the attribute. Typically, you define all required parameters as positional and all optional parameters as named. In this case, the attribute can't be initialized without the required parameter. All other parameters are optional.
> [!NOTE]
-> In Visual Basic, constructors for an attribute class shouldn't use a `ParamArray` argument.
-
- The following code example shows how an attribute that uses the previous constructor can be applied using optional and required parameters. It assumes that the attribute has one required Boolean value and one optional string property.
-
- [!code-cpp[Conceptual.Attributes.Usage#17](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#17)]
+> In Visual Basic, constructors for an attribute class shouldn't use a `ParamArray` argument.
+
+ The following code example shows how an attribute that uses the previous constructor can be applied using optional and required parameters. It assumes that the attribute has one required Boolean value and one optional string property.
+
[!code-csharp[Conceptual.Attributes.Usage#17](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#17)]
- [!code-vb[Conceptual.Attributes.Usage#17](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#17)]
-
-## Declaring Properties
+ [!code-vb[Conceptual.Attributes.Usage#17](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#17)]
+
+## Declaring Properties
If you want to define a named parameter or provide an easy way to return the values stored by your attribute, declare a [property](/previous-versions/visualstudio/visual-studio-2013/65zdfbdt(v=vs.120)). Attribute properties should be declared as public entities with a description of the data type that will be returned. Define the variable that will hold the value of your property and associate it with the `get` and `set` methods. The following code example demonstrates how to implement a property in your attribute:
-
- [!code-cpp[Conceptual.Attributes.Usage#16](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#16)]
+
[!code-csharp[Conceptual.Attributes.Usage#16](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#16)]
- [!code-vb[Conceptual.Attributes.Usage#16](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#16)]
-
-## Custom Attribute Example
+ [!code-vb[Conceptual.Attributes.Usage#16](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#16)]
+
+## Custom Attribute Example
+
+ This section incorporates the previous information and shows how to design an attribute that documents information about the author of a section of code. The attribute in this example stores the name and level of the programmer, and whether the code has been reviewed. It uses three private variables to store the actual values to save. Each variable is represented by a public property that gets and sets the values. Finally, the constructor is defined with two required parameters:
- This section incorporates the previous information and shows how to design an attribute that documents information about the author of a section of code. The attribute in this example stores the name and level of the programmer, and whether the code has been reviewed. It uses three private variables to store the actual values to save. Each variable is represented by a public property that gets and sets the values. Finally, the constructor is defined with two required parameters:
-
- [!code-cpp[Conceptual.Attributes.Usage#4](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#4)]
[!code-csharp[Conceptual.Attributes.Usage#4](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#4)]
- [!code-vb[Conceptual.Attributes.Usage#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#4)]
-
- You can apply this attribute using the full name, `DeveloperAttribute`, or using the abbreviated name, `Developer`, in one of the following ways:
-
- [!code-cpp[Conceptual.Attributes.Usage#12](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.attributes.usage/cpp/source2.cpp#12)]
+ [!code-vb[Conceptual.Attributes.Usage#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#4)]
+
+ You can apply this attribute using the full name, `DeveloperAttribute`, or using the abbreviated name, `Developer`, in one of the following ways:
+
[!code-csharp[Conceptual.Attributes.Usage#12](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.attributes.usage/cs/source2.cs#12)]
- [!code-vb[Conceptual.Attributes.Usage#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#12)]
-
+ [!code-vb[Conceptual.Attributes.Usage#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.attributes.usage/vb/source2.vb#12)]
+
The first example shows the attribute applied with only the required named parameters. The second example shows the attribute applied with both the required and optional parameters.
-
+
## See also
-
diff --git a/docs/standard/base-types/comparing.md b/docs/standard/base-types/comparing.md
index fe41082558ee2..97213ffcd01e3 100644
--- a/docs/standard/base-types/comparing.md
+++ b/docs/standard/base-types/comparing.md
@@ -6,7 +6,6 @@ ms.topic: conceptual
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "value comparisons of strings"
- "LastIndexOf method"
@@ -18,7 +17,6 @@ helpviewer_keywords:
- "EndsWith method"
- "Equals method"
- "StartsWith method"
-ms.assetid: 977dc094-fe19-4955-98ec-d2294d04a4ba
---
# Compare strings in .NET
@@ -52,7 +50,6 @@ The static method p
The following example uses the method to determine the relative values of two strings.
- [!code-cpp[Conceptual.String.BasicOps#6](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#6)]
[!code-csharp[Conceptual.String.BasicOps#6](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#6)]
[!code-vb[Conceptual.String.BasicOps#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#6)]
@@ -69,7 +66,6 @@ The method c
The following example uses the `CompareOrdinal` method to compare the values of two strings.
- [!code-cpp[Conceptual.String.BasicOps#7](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#7)]
[!code-csharp[Conceptual.String.BasicOps#7](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#7)]
[!code-vb[Conceptual.String.BasicOps#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#7)]
@@ -84,7 +80,6 @@ The method compar
The following example uses the method to compare the `string1` object to the `string2` object.
- [!code-cpp[Conceptual.String.BasicOps#8](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#8)]
[!code-csharp[Conceptual.String.BasicOps#8](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#8)]
[!code-vb[Conceptual.String.BasicOps#8](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#8)]
@@ -96,7 +91,6 @@ The method compar
The method can easily determine if two strings are the same. This case-sensitive method returns a `true` or `false` Boolean value. It can be used from an existing class, as illustrated in the next example. The following example uses the `Equals` method to determine whether a string object contains the phrase "Hello World".
- [!code-cpp[Conceptual.String.BasicOps#9](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#9)]
[!code-csharp[Conceptual.String.BasicOps#9](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#9)]
[!code-vb[Conceptual.String.BasicOps#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#9)]
@@ -104,7 +98,6 @@ The method can easil
This method can also be used as a static method. The following example compares two string objects using a static method.
- [!code-cpp[Conceptual.String.BasicOps#10](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#10)]
[!code-csharp[Conceptual.String.BasicOps#10](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#10)]
[!code-vb[Conceptual.String.BasicOps#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#10)]
@@ -114,7 +107,6 @@ The method can easil
You can use the method to determine whether a string object begins with the same characters that encompass another string. This case-sensitive method returns `true` if the current string object begins with the passed string and `false` if it does not. The following example uses this method to determine if a string object begins with "Hello".
- [!code-cpp[Conceptual.String.BasicOps#11](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#11)]
[!code-csharp[Conceptual.String.BasicOps#11](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#11)]
[!code-vb[Conceptual.String.BasicOps#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#11)]
@@ -122,7 +114,6 @@ You can use the
The method compares a passed string to the characters that exist at the end of the current string object. It also returns a Boolean value. The following example checks the end of a string using the `EndsWith` method.
- [!code-cpp[Conceptual.String.BasicOps#12](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#12)]
[!code-csharp[Conceptual.String.BasicOps#12](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#12)]
[!code-vb[Conceptual.String.BasicOps#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#12)]
@@ -134,7 +125,6 @@ You can use the met
The following example uses the `IndexOf` method to search for the first occurrence of the '`l`' character in a string.
- [!code-cpp[Conceptual.String.BasicOps#13](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#13)]
[!code-csharp[Conceptual.String.BasicOps#13](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#13)]
[!code-vb[Conceptual.String.BasicOps#13](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#13)]
@@ -144,7 +134,6 @@ The following example uses the `IndexOf` method to search for the first occurren
The following example uses the `LastIndexOf` method to search for the last occurrence of the '`l`' character in a string.
- [!code-cpp[Conceptual.String.BasicOps#14](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/compare.cpp#14)]
[!code-csharp[Conceptual.String.BasicOps#14](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/compare.cs#14)]
[!code-vb[Conceptual.String.BasicOps#14](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/compare.vb#14)]
diff --git a/docs/standard/base-types/custom-numeric-format-strings.md b/docs/standard/base-types/custom-numeric-format-strings.md
index d92e9cc668991..b02326ca0fb78 100644
--- a/docs/standard/base-types/custom-numeric-format-strings.md
+++ b/docs/standard/base-types/custom-numeric-format-strings.md
@@ -6,7 +6,6 @@ ms.topic: reference
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "numeric format strings [.NET]"
- "formatting [.NET], numbers"
@@ -16,7 +15,6 @@ helpviewer_keywords:
- "format specifiers, numeric"
- "formatting numbers [.NET]"
- "format specifiers, custom numeric format strings"
-ms.assetid: 6f74fd32-6c6b-48ed-8241-3c2b86dea5f4
---
# Custom numeric format strings
@@ -57,7 +55,6 @@ The "00" specifier causes the value to be rounded to the nearest digit preceding
The following example displays several values that are formatted by using custom format strings that include zero placeholders.
-[!code-cpp[Formatting.Numeric.Custom#1](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#1)]
[!code-csharp[Formatting.Numeric.Custom#1](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#1)]
[!code-vb[Formatting.Numeric.Custom#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#1)]
@@ -75,13 +72,11 @@ The "##" format string causes the value to be rounded to the nearest digit prece
The following example displays several values that are formatted by using custom format strings that include digit placeholders.
-[!code-cpp[Formatting.Numeric.Custom#2](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#2)]
[!code-csharp[Formatting.Numeric.Custom#2](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#2)]
[!code-vb[Formatting.Numeric.Custom#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#2)]
To return a result string in which absent digits or leading zeroes are replaced by spaces, use the [composite formatting feature](composite-formatting.md) and specify a field width, as the following example illustrates.
-[!code-cpp[Formatting.Numeric.Custom#12](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/SpaceOrDigit1.cpp#12)]
[!code-csharp[Formatting.Numeric.Custom#12](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/SpaceOrDigit1.cs#12)]
[!code-vb[Formatting.Numeric.Custom#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/SpaceOrDigit1.vb#12)]
@@ -97,7 +92,6 @@ The character that is used as the decimal separator in the result string is not
The following example uses the "." format specifier to define the location of the decimal point in several result strings.
-[!code-cpp[Formatting.Numeric.Custom#3](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#3)]
[!code-csharp[Formatting.Numeric.Custom#3](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#3)]
[!code-vb[Formatting.Numeric.Custom#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#3)]
@@ -119,13 +113,11 @@ You can use group separator and number scaling specifiers in the same format str
The following example illustrates the use of the comma as a group separator.
-[!code-cpp[Formatting.Numeric.Custom#4](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#4)]
[!code-csharp[Formatting.Numeric.Custom#4](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#4)]
[!code-vb[Formatting.Numeric.Custom#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#4)]
The following example illustrates the use of the comma as a specifier for number scaling.
-[!code-cpp[Formatting.Numeric.Custom#5](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#5)]
[!code-csharp[Formatting.Numeric.Custom#5](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#5)]
[!code-vb[Formatting.Numeric.Custom#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#5)]
@@ -139,7 +131,6 @@ A percent sign (%) in a format string causes a number to be multiplied by 100 be
The following example defines several custom format strings that include the "%" custom specifier.
-[!code-cpp[Formatting.Numeric.Custom#6](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#6)]
[!code-csharp[Formatting.Numeric.Custom#6](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#6)]
[!code-vb[Formatting.Numeric.Custom#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#6)]
@@ -153,7 +144,6 @@ A per mille character (‰ or \u2030) in a format string causes a number to be m
The following example defines a custom format string that includes the "‰" custom specifier.
-[!code-cpp[Formatting.Numeric.Custom#9](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#9)]
[!code-csharp[Formatting.Numeric.Custom#9](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#9)]
[!code-vb[Formatting.Numeric.Custom#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#9)]
@@ -167,7 +157,6 @@ If any of the strings "E", "E+", "E-", "e", "e+", or "e-" are present in the for
The following example formats several numeric values using the specifiers for scientific notation.
-[!code-cpp[Formatting.Numeric.Custom#7](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#7)]
[!code-csharp[Formatting.Numeric.Custom#7](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#7)]
[!code-vb[Formatting.Numeric.Custom#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#7)]
@@ -188,7 +177,6 @@ To include a backslash in a result string, you must escape it with another backs
The following example uses the escape character to prevent the formatting operation from interpreting the "#", "0", and "\\" characters as either escape characters or format specifiers. The C# examples uses an additional backslash to ensure that a backslash is interpreted as a literal character.
-[!code-cpp[Formatting.Numeric.Custom#11](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/escape1.cpp#11)]
[!code-csharp-interactive[Formatting.Numeric.Custom#11](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/escape1.cs#11)]
[!code-vb[Formatting.Numeric.Custom#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/escape1.vb#11)]
@@ -210,7 +198,6 @@ Section separators ignore any preexisting formatting associated with a number wh
The following example uses the ";" format specifier to format positive, negative, and zero numbers differently.
-[!code-cpp[Formatting.Numeric.Custom#8](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/custom.cpp#8)]
[!code-csharp-interactive[Formatting.Numeric.Custom#8](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/custom.cs#8)]
[!code-vb[Formatting.Numeric.Custom#8](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/Custom.vb#8)]
@@ -274,7 +261,6 @@ For fixed-point format strings (that is, format strings that do not contain scie
The following example demonstrates two custom numeric format strings. In both cases, the digit placeholder (`#`) displays the numeric data, and all other characters are copied to the result string.
-[!code-cpp[Formatting.Numeric.Custom#10](../../../samples/snippets/cpp/VS_Snippets_CLR/formatting.numeric.custom/cpp/example1.cpp#10)]
[!code-csharp-interactive[Formatting.Numeric.Custom#10](../../../samples/snippets/csharp/VS_Snippets_CLR/formatting.numeric.custom/cs/example1.cs#10)]
[!code-vb[Formatting.Numeric.Custom#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/formatting.numeric.custom/vb/example1.vb#10)]
diff --git a/docs/standard/base-types/padding.md b/docs/standard/base-types/padding.md
index 5dfd5938720f1..8d2b88941495b 100644
--- a/docs/standard/base-types/padding.md
+++ b/docs/standard/base-types/padding.md
@@ -2,47 +2,43 @@
title: "Padding Strings in .NET"
description: Learn how to pad strings in .NET. Use the String.PadLeft and String.PadRight methods to add leading or trailing characters to achieve a specified total length.
ms.date: "03/15/2018"
-dev_langs:
+dev_langs:
- "csharp"
- "vb"
- - "cpp"
-helpviewer_keywords:
+helpviewer_keywords:
- "strings [.NET], padding"
- "white space"
- "PadRight method"
- "PadLeft method"
- "padding strings"
-ms.assetid: 84a9f142-3244-4c90-ba02-21af9bbaff71
---
-# Padding Strings in .NET
+# Pad strings in .NET
Use one of the following methods to create a new string that consists of an original string that is padded with leading or trailing characters to a specified total length. The padding character can be a space or a specified character. The resulting string appears to be either right-aligned or left-aligned. If the original string's length is already equal to or greater than the desired total length, the padding methods return the original string unchanged; for more information, see the **Returns** sections of the two overloads of the and methods.
-
-|Method name|Use|
-|-----------------|---------|
-||Pads a string with leading characters to a specified total length.|
-||Pads a string with trailing characters to a specified total length.|
-
-## PadLeft
-
- The method creates a new string by concatenating enough leading pad characters to an original string to achieve a specified total length. The method uses white space as the padding character and the method enables you to specify your own padding character.
-
- The following code example uses the method to create a new string that is twenty characters long. The example displays "`--------Hello World!`" to the console.
-
- [!code-cpp[Conceptual.String.BasicOps#3](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/padding.cpp#3)]
+
+|Method name|Use|
+|-----------------|---------|
+||Pads a string with leading characters to a specified total length.|
+||Pads a string with trailing characters to a specified total length.|
+
+## PadLeft
+
+ The method creates a new string by concatenating enough leading pad characters to an original string to achieve a specified total length. The method uses white space as the padding character and the method enables you to specify your own padding character.
+
+ The following code example uses the method to create a new string that is twenty characters long. The example displays "`--------Hello World!`" to the console.
+
[!code-csharp[Conceptual.String.BasicOps#3](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/padding.cs#3)]
- [!code-vb[Conceptual.String.BasicOps#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/padding.vb#3)]
-
-## PadRight
-
- The method creates a new string by concatenating enough trailing pad characters to an original string to achieve a specified total length. The method uses white space as the padding character and the method enables you to specify your own padding character.
-
- The following code example uses the method to create a new string that is twenty characters long. The example displays "`Hello World!--------`" to the console.
-
- [!code-cpp[Conceptual.String.BasicOps#4](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/padding.cpp#4)]
+ [!code-vb[Conceptual.String.BasicOps#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/padding.vb#3)]
+
+## PadRight
+
+ The method creates a new string by concatenating enough trailing pad characters to an original string to achieve a specified total length. The method uses white space as the padding character and the method enables you to specify your own padding character.
+
+ The following code example uses the method to create a new string that is twenty characters long. The example displays "`Hello World!--------`" to the console.
+
[!code-csharp[Conceptual.String.BasicOps#4](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/padding.cs#4)]
- [!code-vb[Conceptual.String.BasicOps#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/padding.vb#4)]
-
+ [!code-vb[Conceptual.String.BasicOps#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/padding.vb#4)]
+
## See also
- [Basic String Operations](basic-string-operations.md)
diff --git a/docs/standard/base-types/parsing-other.md b/docs/standard/base-types/parsing-other.md
index ed5b0704ca7f7..e83def37fd03c 100644
--- a/docs/standard/base-types/parsing-other.md
+++ b/docs/standard/base-types/parsing-other.md
@@ -2,50 +2,45 @@
description: "Learn more about: Parsing Other Strings in .NET"
title: "Parsing Other Strings in .NET"
ms.date: "03/30/2017"
-dev_langs:
+dev_langs:
- "csharp"
- "vb"
- - "cpp"
-helpviewer_keywords:
+helpviewer_keywords:
- "Char data type, parsing strings"
- "enumerations [.NET], parsing strings"
- "base types, parsing strings"
- "parsing strings, other strings"
- "Boolean data type, parsing strings"
-ms.assetid: d139bc00-3c4e-4d78-ac9a-5c951b258d28
---
-# Parsing Other Strings in .NET
+# Parse other strings in .NET
-In addition to numeric and strings, you can also parse strings that represent the types , , and into data types.
-
-## Char
+In addition to numeric and strings, you can also parse strings that represent the types , , and into data types.
+
+## Char
+
+ The static parse method associated with the **Char** data type is useful for converting a string that contains a single character into its Unicode value. The following code example parses a string into a Unicode character.
- The static parse method associated with the **Char** data type is useful for converting a string that contains a single character into its Unicode value. The following code example parses a string into a Unicode character.
-
- [!code-cpp[Conceptual.String.Parse#2](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.parse/cpp/parse.cpp#2)]
[!code-csharp[Conceptual.String.Parse#2](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.parse/cs/parse.cs#2)]
- [!code-vb[Conceptual.String.Parse#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.parse/vb/parse.vb#2)]
-
-## Boolean
-
- The **Boolean** data type contains a **Parse** method that you can use to convert a string that represents a Boolean value into an actual **Boolean** type. This method is not case-sensitive and can successfully parse a string containing "True" or "False." The **Parse** method associated with the **Boolean** type can also parse strings that are surrounded by white spaces. If any other string is passed, a is thrown.
-
- The following code example uses the **Parse** method to convert a string into a Boolean value.
-
- [!code-cpp[Conceptual.String.Parse#3](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.parse/cpp/parse.cpp#3)]
+ [!code-vb[Conceptual.String.Parse#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.parse/vb/parse.vb#2)]
+
+## Boolean
+
+ The **Boolean** data type contains a **Parse** method that you can use to convert a string that represents a Boolean value into an actual **Boolean** type. This method is not case-sensitive and can successfully parse a string containing "True" or "False." The **Parse** method associated with the **Boolean** type can also parse strings that are surrounded by white spaces. If any other string is passed, a is thrown.
+
+ The following code example uses the **Parse** method to convert a string into a Boolean value.
+
[!code-csharp[Conceptual.String.Parse#3](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.parse/cs/parse.cs#3)]
- [!code-vb[Conceptual.String.Parse#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.parse/vb/parse.vb#3)]
-
-## Enumeration
-
- You can use the static **Parse** method to initialize an enumeration type to the value of a string. This method accepts the enumeration type you are parsing, the string to parse, and an optional Boolean flag indicating whether or not the parse is case-sensitive. The string you are parsing can contain several values separated by commas, which can be preceded or followed by one or more empty spaces (also called white spaces). When the string contains multiple values, the value of the returned object is the value of all specified values combined with a bitwise OR operation.
-
- The following example uses the **Parse** method to convert a string representation into an enumeration value. The enumeration is initialized to **Thursday** from a string.
-
- [!code-cpp[Conceptual.String.Parse#4](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.parse/cpp/parse.cpp#4)]
+ [!code-vb[Conceptual.String.Parse#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.parse/vb/parse.vb#3)]
+
+## Enumeration
+
+ You can use the static **Parse** method to initialize an enumeration type to the value of a string. This method accepts the enumeration type you are parsing, the string to parse, and an optional Boolean flag indicating whether or not the parse is case-sensitive. The string you are parsing can contain several values separated by commas, which can be preceded or followed by one or more empty spaces (also called white spaces). When the string contains multiple values, the value of the returned object is the value of all specified values combined with a bitwise OR operation.
+
+ The following example uses the **Parse** method to convert a string representation into an enumeration value. The enumeration is initialized to **Thursday** from a string.
+
[!code-csharp[Conceptual.String.Parse#4](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.parse/cs/parse.cs#4)]
- [!code-vb[Conceptual.String.Parse#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.parse/vb/parse.vb#4)]
-
+ [!code-vb[Conceptual.String.Parse#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.parse/vb/parse.vb#4)]
+
## See also
- [Parsing Strings](parsing-strings.md)
diff --git a/docs/standard/base-types/standard-numeric-format-strings.md b/docs/standard/base-types/standard-numeric-format-strings.md
index 199aca156878d..2d88f76072324 100644
--- a/docs/standard/base-types/standard-numeric-format-strings.md
+++ b/docs/standard/base-types/standard-numeric-format-strings.md
@@ -6,7 +6,6 @@ ms.topic: reference
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "numeric format strings [.NET]"
- "formatting [.NET], numbers"
@@ -74,19 +73,16 @@ A standard numeric format string can be used to define the formatting of a numer
- It can be passed to the `TryFormat` method or an overload of the `ToString` method that has a `format` parameter. The following example formats a numeric value as a currency string in the current culture (in this case, the en-US culture).
- [!code-cpp[Formatting.Numeric.Standard#10](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/standardusage1.cpp#10)]
[!code-csharp-interactive[Formatting.Numeric.Standard#10](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/standardusage1.cs#10)]
[!code-vb[Formatting.Numeric.Standard#10](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/standardusage1.vb#10)]
- It can be supplied as the `formatString` argument in a format item used with such methods as , , and . For more information, see [Composite Formatting](composite-formatting.md). The following example uses a format item to insert a currency value in a string.
- [!code-cpp[Formatting.Numeric.Standard#11](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/standardusage1.cpp#11)]
[!code-csharp-interactive[Formatting.Numeric.Standard#11](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/standardusage1.cs#11)]
[!code-vb[Formatting.Numeric.Standard#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/standardusage1.vb#11)]
Optionally, you can supply an `alignment` argument to specify the width of the numeric field and whether its value is right- or left-aligned. The following example left-aligns a currency value in a 28-character field, and it right-aligns a currency value in a 14-character field.
- [!code-cpp[Formatting.Numeric.Standard#12](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/standardusage1.cpp#12)]
[!code-csharp-interactive[Formatting.Numeric.Standard#12](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/standardusage1.cs#12)]
[!code-vb[Formatting.Numeric.Standard#12](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/standardusage1.vb#12)]
@@ -126,8 +122,6 @@ The result string is affected by the formatting information of the current |Defines the number of integer digits that appear in a group.|
The following example formats a value with the currency format specifier:
-
-[!code-cpp[Formatting.Numeric.Standard#1](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#1)]
[!code-csharp[Formatting.Numeric.Standard#1](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#1)]
[!code-vb[Formatting.Numeric.Standard#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#1)]
@@ -146,8 +140,6 @@ The result string is affected by the formatting information of the current |Defines the string that indicates that a number is negative.|
The following example formats an value with the decimal format specifier.
-
-[!code-cpp[Formatting.Numeric.Standard#2](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#2)]
[!code-csharp-interactive[Formatting.Numeric.Standard#2](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#2)]
[!code-vb[Formatting.Numeric.Standard#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#2)]
@@ -170,8 +162,6 @@ The result string is affected by the formatting information of the current |Defines the string that indicates that an exponent is positive.|
The following example formats a value with the exponential format specifier:
-
-[!code-cpp[Formatting.Numeric.Standard#3](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#3)]
[!code-csharp[Formatting.Numeric.Standard#3](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#3)]
[!code-vb[Formatting.Numeric.Standard#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#3)]
@@ -192,8 +182,6 @@ The result string is affected by the formatting information of the current |Defines the default number of decimal digits. This value can be overridden by using the precision specifier.|
The following example formats a and an value with the fixed-point format specifier:
-
-[!code-cpp[Formatting.Numeric.Standard#4](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#4)]
[!code-csharp[Formatting.Numeric.Standard#4](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#4)]
[!code-vb[Formatting.Numeric.Standard#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#4)]
@@ -235,8 +223,6 @@ The result string is affected by the formatting information of the current |Defines the string that indicates that an exponent is positive.|
The following example formats assorted floating-point values with the general format specifier:
-
-[!code-cpp[Formatting.Numeric.Standard#5](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#5)]
[!code-csharp[Formatting.Numeric.Standard#5](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#5)]
[!code-vb[Formatting.Numeric.Standard#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#5)]
@@ -258,8 +244,6 @@ The result string is affected by the formatting information of the current |Defines the default number of decimal digits. This value can be overridden by using a precision specifier.|
The following example formats assorted floating-point values with the number format specifier:
-
-[!code-cpp[Formatting.Numeric.Standard#6](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#6)]
[!code-csharp[Formatting.Numeric.Standard#6](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#6)]
[!code-vb[Formatting.Numeric.Standard#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#6)]
@@ -283,8 +267,6 @@ The following table lists the prope
||Defines the number of integer digits that appear in a group.|
The following example formats floating-point values with the percent format specifier:
-
-[!code-cpp[Formatting.Numeric.Standard#7](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#7)]
[!code-csharp[Formatting.Numeric.Standard#7](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#7)]
[!code-vb[Formatting.Numeric.Standard#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#7)]
@@ -308,8 +290,6 @@ The result string is affected by the formatting information of the current |Defines the string that indicates that an exponent is positive.|
The following example formats a value with the round-trip format specifier.
-
-[!code-cpp[R format specifier with a BigInteger](../../../samples/snippets/standard/base-types/format-strings/biginteger-r.cpp)]
[!code-csharp[R format specifier with a BigInteger](../../../samples/snippets/standard/base-types/format-strings/biginteger-r.cs)]
[!code-vb[R format specifier with a BigInteger](../../../samples/snippets/standard/base-types/format-strings/biginteger-r.vb)]
@@ -332,8 +312,6 @@ The precision specifier indicates the minimum number of digits desired in the re
The result string is not affected by the formatting information of the current object.
The following example formats values with the hexadecimal format specifier.
-
-[!code-cpp[Formatting.Numeric.Standard#9](../../../samples/snippets/cpp/VS_Snippets_CLR/Formatting.Numeric.Standard/cpp/Standard.cpp#9)]
[!code-csharp-interactive[Formatting.Numeric.Standard#9](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.Numeric.Standard/cs/Standard.cs#9)]
[!code-vb[Formatting.Numeric.Standard#9](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.Numeric.Standard/vb/Standard.vb#9)]
diff --git a/docs/standard/base-types/stringbuilder.md b/docs/standard/base-types/stringbuilder.md
index dc07b09d28c96..889f9e59f9a92 100644
--- a/docs/standard/base-types/stringbuilder.md
+++ b/docs/standard/base-types/stringbuilder.md
@@ -5,7 +5,6 @@ ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- - "cpp"
helpviewer_keywords:
- "Remove method"
- "strings [.NET], capacities"
@@ -15,7 +14,6 @@ helpviewer_keywords:
- "Append method"
- "Insert method"
- "strings [.NET], StringBuilder object"
-ms.assetid: 5c14867c-9a99-45bc-ae7f-2686700d377a
---
# Using the StringBuilder Class in .NET
@@ -24,30 +22,22 @@ The object is immutable. Every time you use one of the meth
## Importing the System.Text Namespace
The class is found in the namespace. To avoid having to provide a fully qualified type name in your code, you can import the namespace:
-
- [!code-cpp[Conceptual.StringBuilder#11](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#11)]
[!code-csharp[Conceptual.StringBuilder#11](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#11)]
[!code-vb[Conceptual.StringBuilder#11](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#11)]
## Instantiating a StringBuilder Object
You can create a new instance of the class by initializing your variable with one of the overloaded constructor methods, as illustrated in the following example.
-
- [!code-cpp[Conceptual.StringBuilder#1](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#1)]
[!code-csharp[Conceptual.StringBuilder#1](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#1)]
[!code-vb[Conceptual.StringBuilder#1](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#1)]
## Setting the Capacity and Length
Although the is a dynamic object that allows you to expand the number of characters in the string that it encapsulates, you can specify a value for the maximum number of characters that it can hold. This value is called the capacity of the object and should not be confused with the length of the string that the current holds. For example, you might create a new instance of the class with the string "Hello", which has a length of 5, and you might specify that the object has a maximum capacity of 25. When you modify the , it does not reallocate size for itself until the capacity is reached. When this occurs, the new space is allocated automatically and the capacity is doubled. You can specify the capacity of the class using one of the overloaded constructors. The following example specifies that the `myStringBuilder` object can be expanded to a maximum of 25 spaces.
-
- [!code-cpp[Conceptual.StringBuilder#2](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#2)]
[!code-csharp[Conceptual.StringBuilder#2](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#2)]
[!code-vb[Conceptual.StringBuilder#2](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#2)]
Additionally, you can use the read/write property to set the maximum length of your object. The following example uses the **Capacity** property to define the maximum object length.
-
- [!code-cpp[Conceptual.StringBuilder#3](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#3)]
[!code-csharp[Conceptual.StringBuilder#3](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#3)]
[!code-vb[Conceptual.StringBuilder#3](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#3)]
@@ -70,40 +60,30 @@ The object is immutable. Every time you use one of the meth
### Append
The **Append** method can be used to add text or a string representation of an object to the end of a string represented by the current **StringBuilder**. The following example initializes a **StringBuilder** to "Hello World" and then appends some text to the end of the object. Space is allocated automatically as needed.
-
- [!code-cpp[Conceptual.StringBuilder#4](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#4)]
[!code-csharp[Conceptual.StringBuilder#4](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#4)]
[!code-vb[Conceptual.StringBuilder#4](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#4)]
### AppendFormat
The method adds text to the end of the object. It supports the [composite formatting feature](composite-formatting.md) by calling the implementation of the object or objects to be formatted. Therefore, it accepts the standard format strings for numeric, date and time, and enumeration values, the custom format strings for numeric and date and time values, and the format strings defined for custom types. (For information about formatting, see [Formatting Types](formatting-types.md).) You can use this method to customize the format of variables and append those values to a . The following example uses the method to place an integer value formatted as a currency value at the end of a object.
-
- [!code-cpp[Conceptual.StringBuilder#5](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#5)]
[!code-csharp[Conceptual.StringBuilder#5](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#5)]
[!code-vb[Conceptual.StringBuilder#5](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#5)]
### Insert
The method adds a string or object to a specified position in the current object. The following example uses this method to insert a word into the sixth position of a object.
-
- [!code-cpp[Conceptual.StringBuilder#6](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#6)]
[!code-csharp[Conceptual.StringBuilder#6](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#6)]
[!code-vb[Conceptual.StringBuilder#6](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#6)]
### Remove
You can use the **Remove** method to remove a specified number of characters from the current object, beginning at a specified zero-based index. The following example uses the **Remove** method to shorten a object.
-
- [!code-cpp[Conceptual.StringBuilder#7](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#7)]
[!code-csharp[Conceptual.StringBuilder#7](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#7)]
[!code-vb[Conceptual.StringBuilder#7](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#7)]
### Replace
The **Replace** method can be used to replace characters within the object with another specified character. The following example uses the **Replace** method to search a object for all instances of the exclamation point character (!) and replace them with the question mark character (?).
-
- [!code-cpp[Conceptual.StringBuilder#8](../../../samples/snippets/cpp/VS_Snippets_CLR/Conceptual.StringBuilder/cpp/example.cpp#8)]
[!code-csharp[Conceptual.StringBuilder#8](../../../samples/snippets/csharp/VS_Snippets_CLR/Conceptual.StringBuilder/cs/Example.cs#8)]
[!code-vb[Conceptual.StringBuilder#8](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Conceptual.StringBuilder/vb/Example.vb#8)]
diff --git a/docs/standard/base-types/trimming.md b/docs/standard/base-types/trimming.md
index 73948aee292b3..df8c187405df3 100644
--- a/docs/standard/base-types/trimming.md
+++ b/docs/standard/base-types/trimming.md
@@ -3,11 +3,10 @@ title: "Trimming and Removing Characters from Strings in .NET"
description: Learn to trim blank spaces from the beginning or end of a string, or remove any number of spaces or characters from a specified position in the string in .NET.
ms.date: "07/22/2022"
ms.custom: devdivchpfy22
-dev_langs:
+dev_langs:
- "csharp"
- "vb"
- - "cpp"
-helpviewer_keywords:
+helpviewer_keywords:
- "strings [.NET], removing characters"
- "Remove method"
- "TrimEnd method"
@@ -15,81 +14,70 @@ helpviewer_keywords:
- "trimming characters"
- "TrimStart method"
- "removing characters"
-ms.assetid: ab248dab-70d4-4413-81c6-542d153fd195
---
# Trim and remove characters from strings in .NET
If you're parsing a sentence into individual words, you might end up with words that have blank spaces (also called white spaces) on either end of the word. In this situation, you can use one of the trim methods in the `System.String` class to remove any number of spaces or other characters from a specified position in the string. The following table describes the available trim methods:
-
-|Method name|Use|
-|-----------------|---------|
-||Removes white spaces or characters specified in an array of characters from the beginning and end of a string.|
-||Removes characters specified in an array of characters from the end of a string.|
-||Removes characters specified in an array of characters from the beginning of a string.|
-||Removes a specified number of characters from a specified index position in a string.|
-
+
+|Method name|Use|
+|-----------------|---------|
+||Removes white spaces or characters specified in an array of characters from the beginning and end of a string.|
+||Removes characters specified in an array of characters from the end of a string.|
+||Removes characters specified in an array of characters from the beginning of a string.|
+||Removes a specified number of characters from a specified index position in a string.|
+
## Trim
You can easily remove white spaces from both ends of a string by using the method, as shown in the following example:
-
- [!code-cpp[Conceptual.String.BasicOps#17](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/trimming.cpp#17)]
[!code-csharp[Conceptual.String.BasicOps#17](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/trimming.cs#17)]
- [!code-vb[Conceptual.String.BasicOps#17](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#17)]
-
+ [!code-vb[Conceptual.String.BasicOps#17](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#17)]
+
You can also remove characters that you specify in a character array from the beginning and end of a string. The following example removes white-space characters, periods, and asterisks:
-
+
[!code-csharp[Conceptual.String.BasicOps#22](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/trim2.cs#22)]
- [!code-vb[Conceptual.String.BasicOps#22](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trim2.vb#22)]
-
+ [!code-vb[Conceptual.String.BasicOps#22](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trim2.vb#22)]
+
## TrimEnd
The `String.TrimEnd` method removes characters from the end of a string, creating a new string object. An array of characters is passed to this method to specify the characters to be removed. The order of the elements in the character array doesn't affect the trim operation. The trim stops when a character not specified in the array is found.
-
+
The following example removes the last letters of a string using the `TrimEnd` method. In this example, the position of the `'r'` character and the `'W'` character are reversed to illustrate that the order of characters in the array doesn't matter. Notice that this code removes the last word of `MyString` plus part of the first.
-
- [!code-cpp[Conceptual.String.BasicOps#18](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/trimming.cpp#18)]
[!code-csharp[Conceptual.String.BasicOps#18](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/trimming.cs#18)]
- [!code-vb[Conceptual.String.BasicOps#18](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#18)]
-
+ [!code-vb[Conceptual.String.BasicOps#18](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#18)]
+
This code displays `He` to the console.
-
+
The following example removes the last word of a string using the `TrimEnd` method. In this code, a comma follows the word `Hello` and because the comma isn't specified in the array of characters to trim, the trim ends at the comma.
-
- [!code-cpp[Conceptual.String.BasicOps#19](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/trimming.cpp#19)]
[!code-csharp[Conceptual.String.BasicOps#19](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/trimming.cs#19)]
- [!code-vb[Conceptual.String.BasicOps#19](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#19)]
-
+ [!code-vb[Conceptual.String.BasicOps#19](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#19)]
+
This code displays `Hello,` to the console.
-
+
## TrimStart
The `String.TrimStart` method is similar to the `String.TrimEnd` method except that it creates a new string by removing characters from the beginning of an existing string object. An array of characters is passed to the `TrimStart` method to specify the characters to be removed. As with the `TrimEnd` method, the order of the elements in the character array doesn't affect the trim operation. The trim stops when a character not specified in the array is found.
-
+
The following example removes the first word of a string. In this example, the position of the `'l'` character and the `'H'` character are reversed to illustrate that the order of characters in the array doesn't matter.
-
- [!code-cpp[Conceptual.String.BasicOps#20](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/trimming.cpp#20)]
[!code-csharp[Conceptual.String.BasicOps#20](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/trimming.cs#20)]
- [!code-vb[Conceptual.String.BasicOps#20](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#20)]
-
+ [!code-vb[Conceptual.String.BasicOps#20](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#20)]
+
This code displays `World!` to the console.
-
+
## Remove
The method removes a specified number of characters that begin at a specified position in an existing string. This method assumes a zero-based index.
-
+
The following example removes 10 characters from a string beginning at position five of a zero-based index of the string.
-
- [!code-cpp[Conceptual.String.BasicOps#21](../../../samples/snippets/cpp/VS_Snippets_CLR/conceptual.string.basicops/cpp/trimming.cpp#21)]
[!code-csharp[Conceptual.String.BasicOps#21](../../../samples/snippets/csharp/VS_Snippets_CLR/conceptual.string.basicops/cs/trimming.cs#21)]
- [!code-vb[Conceptual.String.BasicOps#21](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#21)]
-
+ [!code-vb[Conceptual.String.BasicOps#21](../../../samples/snippets/visualbasic/VS_Snippets_CLR/conceptual.string.basicops/vb/trimming.vb#21)]
+
## Replace
You can also remove a specified character or substring from a string by calling the