|
112 | 112 | [!code-csharp-interactive[System.String.Class.Instantiate#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.class.instantiate/cs/program.cs#4)]
|
113 | 113 | [!code-vb[System.String.Class.Instantiate#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb#4)]
|
114 | 114 |
|
115 |
| -- By calling a formatting method to convert a value or object to its string representation. The following example uses the [composite formatting](~/docs/standard/base-types/composite-formatting.md) feature to embed the string representation of two objects into a string. |
| 115 | +- By calling a formatting method to convert a value or object to its string representation. The following example uses the [composite formatting](~/docs/standard/base-types/composite-formatting.md) feature to embed the string representation of two objects into a string. |
116 | 116 |
|
117 | 117 | [!code-cpp[System.String.Class.Instantiate#5](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp#5)]
|
118 | 118 | [!code-csharp-interactive[System.String.Class.Instantiate#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.class.instantiate/cs/program.cs#5)]
|
@@ -6224,40 +6224,34 @@ This method uses the [composite formatting feature](~/docs/standard/base-types/c
|
6224 | 6224 | >
|
6225 | 6225 | > For more information about hash codes, see <xref:System.Object.GetHashCode%2A?displayProperty=nameWithType>.
|
6226 | 6226 |
|
6227 |
| - In desktop apps, you can use the [\<UseRandomizedStringHashAlgorithm> element](~/docs/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element.md) to generate unique hash codes on a per application domain basis. This can reduce the number of collisions and improve the overall performance of insertions and lookups that use hash tables. The following example shows how to use the [\<UseRandomizedStringHashAlgorithm> element](~/docs/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element.md). It defines a to generate unique hash codes on a per application domain basis. This can reduce the number of collisions and improve the overall performance of insertions and lookups that use hash tables. The following example shows how to use the . It defines a `DisplayString` class that includes a private string constant, `s`, whose value is "This is a string." It also includes a `ShowStringHashCode` method that displays the string value and its hash code along with the name of the application domain in which the method is executing. |
| 6227 | + In desktop apps, you can use the [\<UseRandomizedStringHashAlgorithm> element](~/docs/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element.md) to generate unique hash codes on a per application domain basis. This can reduce the number of collisions and improve the overall performance of insertions and lookups that use hash tables. The following example shows how to use the [\<UseRandomizedStringHashAlgorithm> element](~/docs/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element.md). It defines a `DisplayString` class that includes a private string constant, `s`, whose value is "This is a string." It also includes a `ShowStringHashCode` method that displays the string value and its hash code along with the name of the application domain in which the method is executing. |
6228 | 6228 |
|
6229 | 6229 | [!code-csharp[System.String.GetHashCode#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.String.GetHashCode/CS/perdomain.cs#2)]
|
6230 | 6230 | [!code-vb[System.String.GetHashCode#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetHashCode/VB/perdomain.vb#2)]
|
6231 | 6231 |
|
6232 | 6232 | When you run the example without supplying a configuration file, it displays output similar to the following. Note that the hash codes for the string are identical in the two application domains.
|
6233 | 6233 |
|
6234 |
| -``` |
6235 |
| - |
| 6234 | +``` |
6236 | 6235 | String 'This is a string.' in domain 'PerDomain.exe': 941BCEAC
|
6237 |
| -String 'This is a string.' in domain 'NewDomain': 941BCEAC |
6238 |
| - |
| 6236 | +String 'This is a string.' in domain 'NewDomain': 941BCEAC |
6239 | 6237 | ```
|
6240 | 6238 |
|
6241 | 6239 | However, if you add the following configuration file to the example's directory and then run the example, the hash codes for the same string will differ by application domain.
|
6242 | 6240 |
|
6243 |
| -```xml |
6244 |
| - |
| 6241 | +```xml |
6245 | 6242 | <?xml version ="1.0"?>
|
6246 | 6243 | <configuration>
|
6247 | 6244 | <runtime>
|
6248 | 6245 | <UseRandomizedStringHashAlgorithm enabled="1" />
|
6249 | 6246 | </runtime>
|
6250 |
| -</configuration> |
6251 |
| - |
| 6247 | +</configuration> |
6252 | 6248 | ```
|
6253 | 6249 |
|
6254 | 6250 | When the configuration file is present, the example displays the following output:
|
6255 | 6251 |
|
6256 | 6252 | ```
|
6257 |
| - |
6258 |
| -String 'This is a string.' in domain 'PerDomain.exe': 5435776D |
6259 |
| -String 'This is a string.' in domain 'NewDomain': 75CC8236 |
6260 |
| - |
| 6253 | +String 'This is a string.' in domain 'PerDomain.exe': 5435776D |
| 6254 | +String 'This is a string.' in domain 'NewDomain': 75CC8236 |
6261 | 6255 | ```
|
6262 | 6256 |
|
6263 | 6257 | > [!IMPORTANT]
|
|
0 commit comments