C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# String IsInterned()The C# IsInterned() method is used to get reference of the specified string. The difference between Intern() and IsInterned() is that Intern() method interns the string if it is not interned but IsInterned() doesn't do so. In such case, IsInterned() method returns null. Signature public static string IsInterned(String str) Parameterstr: it is a string type parameter. Return It returns a reference. C# String IsInterned() Method Exampleusing System; public class StringExample { public static void Main(string[] args) { string s1 = "Hello C#"; string s2 = string.Intern(s1); string s3 = string.IsInterned(s1); Console.WriteLine(s1); Console.WriteLine(s2); Console.WriteLine(s3); } } Output: Hello C# Hello C# Hello C# C# String Intern() vs IsInterned() Exampleusing System; public class StringExample { public static void Main(string[] args) { string a = new string(new[] {'a'}); string b = new string(new[] {'b'}); string.Intern(a); // Interns it Console.WriteLine(string.IsInterned(a) != null);//True string.IsInterned(b); // Doesn't intern it Console.WriteLine(string.IsInterned(b) != null);//False } } Output: True False
Next TopicC# String IsNormalized()
|