From 48187c2c02b236fc36627771a6aeb0054ea2c3ba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:06:47 +0000 Subject: [PATCH 1/7] Initial plan From 5f59568220059f055cdad1ac2c8519fbc771514d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:12:13 +0000 Subject: [PATCH 2/7] Fix String.Intern docs: update sample and clarify NativeAOT behavior Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/6d9edca7-bde5-44cb-b6f9-49eec45b8cad Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- .../csharp/System/String/Intern/Intern.csproj | 9 ++++++++ .../System/String/Intern/string_intern.cs | 22 ++++++++++++------- .../System/String/Intern/string_intern.fs | 22 ++++++++++++------- .../System/String/Intern/string_intern.vb | 22 ++++++++++++------- xml/System/String.xml | 11 ++++++++-- 5 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 snippets/csharp/System/String/Intern/Intern.csproj diff --git a/snippets/csharp/System/String/Intern/Intern.csproj b/snippets/csharp/System/String/Intern/Intern.csproj new file mode 100644 index 00000000000..f9929d13fb7 --- /dev/null +++ b/snippets/csharp/System/String/Intern/Intern.csproj @@ -0,0 +1,9 @@ + + + + Exe + net10.0 + enable + + + diff --git a/snippets/csharp/System/String/Intern/string_intern.cs b/snippets/csharp/System/String/Intern/string_intern.cs index 1c5cb3e213b..8f14ccb26f7 100644 --- a/snippets/csharp/System/String/Intern/string_intern.cs +++ b/snippets/csharp/System/String/Intern/string_intern.cs @@ -7,22 +7,28 @@ class Sample { public static void Main() { - string s1 = "MyTest"; + string s1 = new StringBuilder().Append("My").Append("Test").ToString(); string s2 = new StringBuilder().Append("My").Append("Test").ToString(); - string s3 = String.Intern(s2); Console.WriteLine($"s1 == {s1}"); Console.WriteLine($"s2 == {s2}"); - Console.WriteLine($"s3 == {s3}"); - Console.WriteLine($"Is s2 the same reference as s1?: {(Object)s2 == (Object)s1}"); - Console.WriteLine($"Is s3 the same reference as s1?: {(Object)s3 == (Object)s1}"); + Console.WriteLine($"Are s1 and s2 equal in value? {s1 == s2}"); + Console.WriteLine($"Are s1 and s2 the same reference? {Object.ReferenceEquals(s1, s2)}"); + + string i1 = String.Intern(s1); + string i2 = String.Intern(s2); + Console.WriteLine($"After interning:"); + Console.WriteLine($" Are i1 and i2 equal in value? {i1 == i2}"); + Console.WriteLine($" Are i1 and i2 the same reference? {Object.ReferenceEquals(i1, i2)}"); } } /* This example produces the following results: s1 == MyTest s2 == MyTest -s3 == MyTest -Is s2 the same reference as s1?: False -Is s3 the same reference as s1?: True +Are s1 and s2 equal in value? True +Are s1 and s2 the same reference? False +After interning: + Are i1 and i2 equal in value? True + Are i1 and i2 the same reference? True */ // diff --git a/snippets/fsharp/System/String/Intern/string_intern.fs b/snippets/fsharp/System/String/Intern/string_intern.fs index 7ac4d82ca6d..ea4eaa80d7c 100644 --- a/snippets/fsharp/System/String/Intern/string_intern.fs +++ b/snippets/fsharp/System/String/Intern/string_intern.fs @@ -4,20 +4,26 @@ module string_intern.fs open System open System.Text -let s1 = "MyTest" +let s1 = StringBuilder().Append("My").Append("Test").ToString() let s2 = StringBuilder().Append("My").Append("Test").ToString() -let s3 = String.Intern s2 printfn $"s1 = {s1}" printfn $"s2 = {s2}" -printfn $"s3 = {s3}" -printfn $"Is s2 the same reference as s1?: {s2 :> obj = s1 :> obj}" -printfn $"Is s3 the same reference as s1?: {s3 :> obj = s1 :> obj}" +printfn $"Are s1 and s2 equal in value? {s1 = s2}" +printfn $"Are s1 and s2 the same reference? {Object.ReferenceEquals(s1, s2)}" + +let i1 = String.Intern s1 +let i2 = String.Intern s2 +printfn "After interning:" +printfn $" Are i1 and i2 equal in value? {i1 = i2}" +printfn $" Are i1 and i2 the same reference? {Object.ReferenceEquals(i1, i2)}" (* This example produces the following results: s1 = MyTest s2 = MyTest -s3 = MyTest -Is s2 the same reference as s1?: False -Is s3 the same reference as s1?: True +Are s1 and s2 equal in value? True +Are s1 and s2 the same reference? False +After interning: + Are i1 and i2 equal in value? True + Are i1 and i2 the same reference? True *) // diff --git a/snippets/visualbasic/System/String/Intern/string_intern.vb b/snippets/visualbasic/System/String/Intern/string_intern.vb index d07c8424b4c..c8805b9125a 100644 --- a/snippets/visualbasic/System/String/Intern/string_intern.vb +++ b/snippets/visualbasic/System/String/Intern/string_intern.vb @@ -4,21 +4,27 @@ Imports System.Text Class Sample Public Shared Sub Main() - Dim s1 As String = "MyTest" + Dim s1 As String = New StringBuilder().Append("My").Append("Test").ToString() Dim s2 As String = New StringBuilder().Append("My").Append("Test").ToString() - Dim s3 As String = String.Intern(s2) Console.WriteLine($"s1 = {s1}") Console.WriteLine($"s2 = {s2}") - Console.WriteLine($"s3 = {s3}") - Console.WriteLine($"Is s2 the same reference as s1?: {s2 Is s1}") - Console.WriteLine($"Is s3 the same reference as s1?: {s3 Is s1}") + Console.WriteLine($"Are s1 and s2 equal in value? {s1 = s2}") + Console.WriteLine($"Are s1 and s2 the same reference? {s1 Is s2}") + + Dim i1 As String = String.Intern(s1) + Dim i2 As String = String.Intern(s2) + Console.WriteLine("After interning:") + Console.WriteLine($" Are i1 and i2 equal in value? {i1 = i2}") + Console.WriteLine($" Are i1 and i2 the same reference? {i1 Is i2}") End Sub End Class ' 's1 = MyTest 's2 = MyTest -'s3 = MyTest -'Is s2 the same reference as s1?: False -'Is s3 the same reference as s1?: True +'Are s1 and s2 equal in value? True +'Are s1 and s2 the same reference? False +'After interning: +' Are i1 and i2 equal in value? True +' Are i1 and i2 the same reference? True ' ' diff --git a/xml/System/String.xml b/xml/System/String.xml index 59a0f9dc6fc..8afb16c90a2 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -8738,10 +8738,17 @@ The following console application prompts the users to enter one or more adjecti A string to search for in the intern pool. Retrieves the system's reference to the specified . The system's reference to , if it is interned; otherwise, a new reference to a string with the value of . - For more information about this API, see Supplemental API remarks for String.Intern. + + [!NOTE] +> While `String.Intern` guarantees that two strings with equal values return the same interned reference, it doesn't guarantee that the returned reference is the same as a string literal. String literal interning (where a literal like `"MyTest"` is automatically added to the intern pool) is an implementation detail that varies by runtime. In particular, NativeAOT doesn't automatically add string literals to the intern pool. If you need to check reference equality with a literal, intern the literal explicitly using `String.Intern`. + +For more information about this API, see Supplemental API remarks for String.Intern. + ]]> + Date: Thu, 26 Mar 2026 18:29:35 +0000 Subject: [PATCH 3/7] Remove Intern.csproj from C# snippet folder Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/59f89597-f5c4-4e46-8744-2aadfca3cb8a Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- snippets/csharp/System/String/Intern/Intern.csproj | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 snippets/csharp/System/String/Intern/Intern.csproj diff --git a/snippets/csharp/System/String/Intern/Intern.csproj b/snippets/csharp/System/String/Intern/Intern.csproj deleted file mode 100644 index f9929d13fb7..00000000000 --- a/snippets/csharp/System/String/Intern/Intern.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - net10.0 - enable - - - From 9b218b1e4334d9b09727957e1fee6e0621ec315f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:56:21 +0000 Subject: [PATCH 4/7] Shorten String.Intern note; defer NativeAOT details to supplemental doc Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/e57c0322-d684-4c49-8e9b-c3465a386dcd Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- xml/System/String.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xml/System/String.xml b/xml/System/String.xml index 8afb16c90a2..eaf50542ede 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -8741,9 +8741,7 @@ The following console application prompts the users to enter one or more adjecti [!NOTE] -> While `String.Intern` guarantees that two strings with equal values return the same interned reference, it doesn't guarantee that the returned reference is the same as a string literal. String literal interning (where a literal like `"MyTest"` is automatically added to the intern pool) is an implementation detail that varies by runtime. In particular, NativeAOT doesn't automatically add string literals to the intern pool. If you need to check reference equality with a literal, intern the literal explicitly using `String.Intern`. - -For more information about this API, see Supplemental API remarks for String.Intern. +> While `String.Intern` guarantees that two strings with equal values return the same interned reference, it doesn't guarantee that the returned reference is the same as a string literal. For more information about this API, see Supplemental API remarks for String.Intern. ]]> From 9f49e0cc04fe1fd5def9103f6bea5446d2632bdb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Mar 2026 01:08:40 +0000 Subject: [PATCH 5/7] Fix String.IsInterned sample: use constructed strings, show reference equality, remove ngen mention Agent-Logs-Url: https://github.com/dotnet/dotnet-api-docs/sessions/b0741bac-7a60-4afc-b6e6-5e4289eff6b7 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- .../csharp/System/String/IsInterned/isin.cs | 51 ++++++++----------- .../fsharp/System/String/IsInterned/isin.fs | 48 +++++++---------- .../System/String/IsInterned/isin.vb | 50 ++++++++---------- xml/System/String.xml | 5 +- 4 files changed, 59 insertions(+), 95 deletions(-) diff --git a/snippets/csharp/System/String/IsInterned/isin.cs b/snippets/csharp/System/String/IsInterned/isin.cs index e6bf976c358..e7dc8a16d93 100644 --- a/snippets/csharp/System/String/IsInterned/isin.cs +++ b/snippets/csharp/System/String/IsInterned/isin.cs @@ -2,46 +2,35 @@ // Sample for String.IsInterned(String) using System; using System.Text; -using System.Runtime.CompilerServices; -// In the .NET Framework 2.0 the following attribute declaration allows you to -// avoid the use of the interning when you use NGEN.exe to compile an assembly -// to the native image cache. -[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)] class Sample { public static void Main() { - // String str1 is known at compile time, and is automatically interned. - String str1 = "abcd"; + // Constructed strings are not automatically interned. + string s1 = new StringBuilder().Append("My").Append("Test").ToString(); + string s2 = new StringBuilder().Append("My").Append("Test").ToString(); - // Constructed string, str2, is not explicitly or automatically interned. - String str2 = new StringBuilder().Append("wx").Append("yz").ToString(); - Console.WriteLine(); - Test(1, str1); - Test(2, str2); - } + // Neither string is in the intern pool yet. + Console.WriteLine($"Is s1 interned? {String.IsInterned(s1) != null}"); + Console.WriteLine($"Is s2 interned? {String.IsInterned(s2) != null}"); - public static void Test(int sequence, String str) - { - Console.Write("{0}) The string, '", sequence); - String strInterned = String.IsInterned(str); - if (strInterned == null) - Console.WriteLine("{0}', is not interned.", str); - else - Console.WriteLine("{0}', is interned.", strInterned); - } -} + // Intern s1 explicitly. + string i1 = String.Intern(s1); -//This example produces the following results: + // Now s2 can be found in the intern pool. + string i2 = String.IsInterned(s2); -//1) The string, 'abcd', is interned. -//2) The string, 'wxyz', is not interned. - -//If you use NGEN.exe to compile the assembly to the native image cache, this -//example produces the following results: + Console.WriteLine($"Is s2 interned after interning s1? {i2 != null}"); + Console.WriteLine($"Are i1 and i2 the same reference? {Object.ReferenceEquals(i1, i2)}"); + } +} -//1) The string, 'abcd', is not interned. -//2) The string, 'wxyz', is not interned. +// This example produces the following results: +// +// Is s1 interned? False +// Is s2 interned? False +// Is s2 interned after interning s1? True +// Are i1 and i2 the same reference? True // \ No newline at end of file diff --git a/snippets/fsharp/System/String/IsInterned/isin.fs b/snippets/fsharp/System/String/IsInterned/isin.fs index cc9b46a28f8..0488533f81b 100644 --- a/snippets/fsharp/System/String/IsInterned/isin.fs +++ b/snippets/fsharp/System/String/IsInterned/isin.fs @@ -3,41 +3,29 @@ module isin.fs // Sample for String.IsInterned(String) open System open System.Text -open System.Runtime.CompilerServices -// In the .NET Framework 2.0 the following attribute declaration allows you to -// avoid the use of the interning when you use NGEN.exe to compile an assembly -// to the native image cache. -[] -do () +// Constructed strings are not automatically interned. +let s1 = StringBuilder().Append("My").Append("Test").ToString() +let s2 = StringBuilder().Append("My").Append("Test").ToString() -let test sequence str = - printf $"%d{sequence}) The string, '" - let strInterned = String.IsInterned str - if isNull strInterned then - printfn $"{str}', is not interned." - else - printfn $"{strInterned}', is interned." +// Neither string is in the intern pool yet. +printfn $"Is s1 interned? {String.IsInterned(s1) <> null}" +printfn $"Is s2 interned? {String.IsInterned(s2) <> null}" -// String str1 is known at compile time, and is automatically interned. -let str1 = "abcd" +// Intern s1 explicitly. +let i1 = String.Intern(s1) -// Constructed string, str2, is not explicitly or automatically interned. -let str2 = StringBuilder().Append("wx").Append("yz").ToString() -printfn "" -test 1 str1 -test 2 str2 +// Now s2 can be found in the intern pool. +let i2 = String.IsInterned(s2) +printfn $"Is s2 interned after interning s1? {i2 <> null}" +printfn $"Are i1 and i2 the same reference? {Object.ReferenceEquals(i1, i2)}" -//This example produces the following results: - -//1) The string, 'abcd', is interned. -//2) The string, 'wxyz', is not interned. - -//If you use NGEN.exe to compile the assembly to the native image cache, this -//example produces the following results: - -//1) The string, 'abcd', is not interned. -//2) The string, 'wxyz', is not interned. +// This example produces the following results: +// +// Is s1 interned? False +// Is s2 interned? False +// Is s2 interned after interning s1? True +// Are i1 and i2 the same reference? True // diff --git a/snippets/visualbasic/System/String/IsInterned/isin.vb b/snippets/visualbasic/System/String/IsInterned/isin.vb index 89cec08e218..2296539ad2c 100644 --- a/snippets/visualbasic/System/String/IsInterned/isin.vb +++ b/snippets/visualbasic/System/String/IsInterned/isin.vb @@ -1,43 +1,33 @@ ' ' Sample for String.IsInterned(String) Imports System.Text -Imports System.Runtime.CompilerServices -' In the .NET Framework 2.0 the following attribute declaration allows you to -' avoid the use of the interning when you use NGEN.exe to compile an assembly -' to the native image cache. - Class Sample Public Shared Sub Main() - ' String str1 is known at compile time, and is automatically interned. - Dim str1 As [String] = "abcd" + ' Constructed strings are not automatically interned. + Dim s1 As String = New StringBuilder().Append("My").Append("Test").ToString() + Dim s2 As String = New StringBuilder().Append("My").Append("Test").ToString() - ' Constructed string, str2, is not explicitly or automatically interned. - Dim str2 As [String] = New StringBuilder().Append("wx").Append("yz").ToString() - Console.WriteLine() - Test(1, str1) - Test(2, str2) - End Sub + ' Neither string is in the intern pool yet. + Console.WriteLine($"Is s1 interned? {String.IsInterned(s1) IsNot Nothing}") + Console.WriteLine($"Is s2 interned? {String.IsInterned(s2) IsNot Nothing}") - Public Shared Sub Test(ByVal sequence As Integer, ByVal str As [String]) - Console.Write("{0}) The string, '", sequence) - Dim strInterned As [String] = [String].IsInterned(str) - If strInterned Is Nothing Then - Console.WriteLine("{0}', is not interned.", str) - Else - Console.WriteLine("{0}', is interned.", strInterned) - End If - End Sub -End Class + ' Intern s1 explicitly. + Dim i1 As String = String.Intern(s1) -'This example produces the following results: + ' Now s2 can be found in the intern pool. + Dim i2 As String = String.IsInterned(s2) -'1) The string, 'abcd', is interned. -'2) The string, 'wxyz', is not interned. + Console.WriteLine($"Is s2 interned after interning s1? {i2 IsNot Nothing}") + Console.WriteLine($"Are i1 and i2 the same reference? {Object.ReferenceEquals(i1, i2)}") + End Sub +End Class -'If you use NGEN.exe to compile the assembly to the native image cache, this -'example produces the following results: +' This example produces the following results: +' +' Is s1 interned? False +' Is s2 interned? False +' Is s2 interned after interning s1? True +' Are i1 and i2 the same reference? True -'1) The string, 'abcd', is not interned. -'2) The string, 'wxyz', is not interned. ' \ No newline at end of file diff --git a/xml/System/String.xml b/xml/System/String.xml index eaf50542ede..830fb9ec316 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -8832,11 +8832,8 @@ This method does not return a Boolean value. If you call the method because you :::code language="fsharp" source="~/snippets/fsharp/System/String/IsInterned/isinternedex1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/System/String/IsInterned/isinternedex1.vb" id="Snippet1"::: -> [!NOTE] -> You can override the use of the intern pool when you use [Ngen.exe (Native Image Generator)](/dotnet/framework/tools/ngen-exe-native-image-generator) to install an assembly to the native image cache on a local computer. For more information, see Performance Considerations in the Remarks section for the method. - ## Examples -The following example demonstrates that literal strings are interned automatically by the compiler. +The following example demonstrates how to use `IsInterned` to check whether strings are in the intern pool and to verify reference equality of interned strings. :::code language="csharp" source="~/snippets/csharp/System/String/IsInterned/isin.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/IsInterned/isin.fs" id="Snippet1"::: From 37530f2b8c7ffe64959df12717785c8c8b35219c Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 30 Mar 2026 11:53:22 -0700 Subject: [PATCH 6/7] fix compile errors --- .../fsharp/System/String/Intern/fs.fsproj | 4 +- .../System/String/IsInterned/Program.vb | 7 +++ .../System/String/IsInterned/Project.vbproj | 8 +++ .../System/String/IsInterned/isin.vb | 27 +++++----- .../System/String/IsInterned/isinternedex1.vb | 54 +++++++++---------- 5 files changed, 57 insertions(+), 43 deletions(-) create mode 100644 snippets/visualbasic/System/String/IsInterned/Program.vb create mode 100644 snippets/visualbasic/System/String/IsInterned/Project.vbproj diff --git a/snippets/fsharp/System/String/Intern/fs.fsproj b/snippets/fsharp/System/String/Intern/fs.fsproj index c7bdb863be3..6d494f6fa40 100644 --- a/snippets/fsharp/System/String/Intern/fs.fsproj +++ b/snippets/fsharp/System/String/Intern/fs.fsproj @@ -5,8 +5,6 @@ - - - \ No newline at end of file + diff --git a/snippets/visualbasic/System/String/IsInterned/Program.vb b/snippets/visualbasic/System/String/IsInterned/Program.vb new file mode 100644 index 00000000000..ffe8965f852 --- /dev/null +++ b/snippets/visualbasic/System/String/IsInterned/Program.vb @@ -0,0 +1,7 @@ +Public Class Program + Public Shared Sub Main() + IsInExample.Run() + IsInternedExample.Run() + End Sub + +End Class diff --git a/snippets/visualbasic/System/String/IsInterned/Project.vbproj b/snippets/visualbasic/System/String/IsInterned/Project.vbproj new file mode 100644 index 00000000000..a15a29bf12c --- /dev/null +++ b/snippets/visualbasic/System/String/IsInterned/Project.vbproj @@ -0,0 +1,8 @@ + + + + Exe + net10.0 + + + diff --git a/snippets/visualbasic/System/String/IsInterned/isin.vb b/snippets/visualbasic/System/String/IsInterned/isin.vb index 2296539ad2c..9918046697b 100644 --- a/snippets/visualbasic/System/String/IsInterned/isin.vb +++ b/snippets/visualbasic/System/String/IsInterned/isin.vb @@ -1,9 +1,10 @@ -' -' Sample for String.IsInterned(String) +' Sample for String.IsInterned(String) Imports System.Text -Class Sample - Public Shared Sub Main() +Module IsInExample + Public Sub Run() + ' + ' Constructed strings are not automatically interned. Dim s1 As String = New StringBuilder().Append("My").Append("Test").ToString() Dim s2 As String = New StringBuilder().Append("My").Append("Test").ToString() @@ -20,14 +21,14 @@ Class Sample Console.WriteLine($"Is s2 interned after interning s1? {i2 IsNot Nothing}") Console.WriteLine($"Are i1 and i2 the same reference? {Object.ReferenceEquals(i1, i2)}") - End Sub -End Class -' This example produces the following results: -' -' Is s1 interned? False -' Is s2 interned? False -' Is s2 interned after interning s1? True -' Are i1 and i2 the same reference? True + ' This example produces the following results: + ' + ' Is s1 interned? False + ' Is s2 interned? False + ' Is s2 interned after interning s1? True + ' Are i1 and i2 the same reference? True -' \ No newline at end of file + ' + End Sub +End Module diff --git a/snippets/visualbasic/System/String/IsInterned/isinternedex1.vb b/snippets/visualbasic/System/String/IsInterned/isinternedex1.vb index 24f30cc9f35..1b6d38d4bb2 100644 --- a/snippets/visualbasic/System/String/IsInterned/isinternedex1.vb +++ b/snippets/visualbasic/System/String/IsInterned/isinternedex1.vb @@ -2,31 +2,31 @@ ' Uses IsInterned to determine whether a string is interned (True) or not (False). Option Strict On -' -Module Example - Public Sub Main() - Dim str1 As String = "a" - Dim str2 As String = str1 + "b" - Dim str3 As String = str2 + "c" - Dim strings() As String = { "value", "part1" + "_" + "part2", str3, - String.Empty, Nothing } - For Each value In strings - If value Is Nothing Then Continue For - - Dim interned As Boolean = (String.IsInterned(value) IsNot Nothing) - If interned Then - Console.WriteLine("'{0}' is in the string intern pool.", - value) - Else - Console.WriteLine("'{0}' is not in the string intern pool.", - value) - End If - Next - End Sub +Module IsInternedExample + Public Sub Run() + ' + + Dim str1 As String = "a" + Dim str2 As String = str1 + "b" + Dim str3 As String = str2 + "c" + Dim strings() As String = {"value", "part1" + "_" + "part2", str3, + String.Empty, Nothing} + For Each value In strings + If value Is Nothing Then Continue For + + Dim interned As Boolean = (String.IsInterned(value) IsNot Nothing) + If interned Then + Console.WriteLine($"'{value}' is in the string intern pool.") + Else + Console.WriteLine($"'{value}' is not in the string intern pool.") + End If + Next + + ' The example displays the following output: + ' 'value' is in the string intern pool. + ' 'part1_part2' is in the string intern pool. + ' 'abc' is not in the string intern pool. + ' '' is in the string intern pool. + ' + End Sub End Module -' The example displays the following output: -' 'value' is in the string intern pool. -' 'part1_part2' is in the string intern pool. -' 'abc' is not in the string intern pool. -' '' is in the string intern pool. -' From a5e833aae031cec62a8781a8185d0699a485798b Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 30 Mar 2026 11:59:43 -0700 Subject: [PATCH 7/7] Fix link format Updated remarks section to improve formatting and clarity. --- xml/System/String.xml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xml/System/String.xml b/xml/System/String.xml index 830fb9ec316..067ba4c8b8b 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -8740,9 +8740,11 @@ The following console application prompts the users to enter one or more adjecti The system's reference to , if it is interned; otherwise, a new reference to a string with the value of . [!NOTE] -> While `String.Intern` guarantees that two strings with equal values return the same interned reference, it doesn't guarantee that the returned reference is the same as a string literal. For more information about this API, see Supplemental API remarks for String.Intern. - ]]> + > ![NOTE] + > While `String.Intern` guarantees that two strings with equal values return the same interned reference, it doesn't guarantee that the returned reference is the same as a string literal. + + For more information about this API, see [Supplemental API remarks for String.Intern](/dotnet/fundamentals/runtime-libraries/system-string-intern). + ]]>