C# | How to retrieve the system's reference to the specified String Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report String.Intern(String) Method is used to retrieve the system's reference to the specified String. This method uses the intern pool to search for a string equal to the value of the specified string. If such a string exists, then its reference in the intern pool is returned, or if the string doesn't exist, a reference of the specified string is added to the intern pool, then that reference is returned. Here the intern pool is a table that contains a single reference to each unique literal string declared or created programmatically in your program.Syntax: public static string Intern (string strA); Here strA is a string to search for in the intern pool.Return Value: The return type of this method is System.String. This method will return a system's reference to strA if it is interned. Otherwise, a new reference to a string with the value of strA.Exception: This method will give ArgumentNullException if the str is null.Below given are some examples to understand the implementation in a better way: Example 1: CSharp // C# program to illustrate Intern() method using System; public class GFG { // main method public static void Main(string[] args) { // string string strA = "This is C# tutorial"; // retrieve the system reference // of strA string by // using Intern() method string strB = string.Intern(strA); // Display the strings Console.WriteLine(strA); Console.WriteLine(strB); } } Output: This is C# tutorial This is C# tutorial Example 2: CSharp // C# program to illustrate the // use of Intern() Method using System; class GFG { public static void Main() { // strings string strA = "GeeksforGeeks"; string strB = "GFG"; string strC = "Noida"; string strD = String.Intern(strA); string strE = String.Intern(strC); // Display string Console.WriteLine("string A == '{0}'", strA); Console.WriteLine("string B == '{0}'", strB); Console.WriteLine("string C == '{0}'", strC); Console.WriteLine("string D == '{0}'", strD); Console.WriteLine("string E == '{0}'", strE); Console.WriteLine(); // Check the reference of strings Console.WriteLine("Is string A have the same reference as string B: {0}", (Object)strA == (Object)strB); Console.WriteLine("Is string B have the same reference as string C: {0}", (Object)strB == (Object)strC); Console.WriteLine("Is string D have the same reference as string E: {0}", (Object)strD == (Object)strE); Console.WriteLine("Is string A have the same reference as string D: {0}", (Object)strA == (Object)strD); Console.WriteLine("Is string E have the same reference as string C: {0}", (Object)strE == (Object)strC); } } Output: string A == 'GeeksforGeeks' string B == 'GFG' string C == 'Noida' string D == 'GeeksforGeeks' string E == 'Noida' Is string A have the same reference as string B: False Is string B have the same reference as string C: False Is string D have the same reference as string E: False Is string A have the same reference as string D: True Is string E have the same reference as string C: True Reference: https://learn.microsoft.com/en-us/dotnet/api/system.string.intern?view=netframework-4.7.2#definition Comment More infoAdvertise with us Next Article C# | How to retrieve a reference to a specified String A ankita_saini Follow Improve Article Tags : C# CSharp-method CSharp-string Similar Reads C# | How to retrieve a reference to a specified String String.IsInterned(String) Method method is used to retrieve a reference to a specified String. This method looks up the specified string in the intern pool. If the specified string has already been interned, a reference to that instance is returned. Otherwise, null is returned. Here the intern pool 3 min read C# Program to Get the Path of System Directory Using Environment Class In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, 2 min read C# Program to Get the Machine Name or Host Name Using Environment Class Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that retrieves command-line arguments information, exit codes information, environme 1 min read C# Program to Get Current Stack Trace Information Using Environment Class In C#, Environment Class provides information about the current platform and manipulates, the current platform. It is useful for getting and setting various operating system-related information. We can use it in such a way that it retrieves command-line arguments information, exit codes information, 2 min read C# Program to Print the Current Assembly Name Using GetExecutingAssembly() Method In C#, GetExecutingAssembly() method is the method of Assembly class. This method returns the assembly that contains the code that is currently executing. To use this method we have to use System.Reflection in our program. Syntax: public static System.Reflection.Assembly GetExecutingAssembly (); It 1 min read Strings in C A string is an array of characters terminated by a special character '\0' (null character). This null character marks the end of the string and is essential for proper string manipulation.Unlike many modern languages, C does not have a built-in string data type. Instead, strings are implemented as a 6 min read Like