C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# String Intern(String str)The C# Intern() method is used to retrieve reference to the specified String. It goes to intern pool (memory area) to search for a string equal to the specified String. If such a string exists, its reference in the intern pool is returned. If the string does not exist, a reference to specified String is added to the intern pool, then that reference is returned. SignatureThe signature of intern method is given below: public static string Intern(String str) Parametersstr: it is a parameter of type string. C# String Intern() Method Exampleusing System; public class StringExample { public static void Main(string[] args) { string s1 = "Hello C#"; string s2 = string.Intern(s1); Console.WriteLine(s1); Console.WriteLine(s2); } } Output: Hello C# Hello C#
Next TopicC# String IsInterned()
|