In the c# String Intern() method is used to retrieve reference to the specified String that mean optimizes string memory and performance and It allows us to put strings in the runtime's shared string pool.
Syntax
public static string Intern(String str)
Parameters
str: it is a parameter of type string.
C# String Intern() Method Example
using System;
public class Program
{
public static void Main()
{
string str = "Hello FindAndSolve";
string str1 = string.Intern(str);
Console.WriteLine(str);
Console.WriteLine(str1);
}
}
Output
Hello FindAndSolve
Hello FindAndSolve