String Isinterned() - C# Tutorial
C# Course / Strings / String Isinterned()

String Isinterned()

BLUF: Mastering String Isinterned() is essential for building robust applications with the .NET ecosystem. This tutorial provides clear explanations and practical examples to help you understand and apply this C# concept.
Enterprise Development Tip: String Isinterned()

C# is a powerful, modern language for enterprise solutions. Discover how String Isinterned() enhances your development workflow in the guide below.

The C# IsInterned method is employed to obtain the reference of the specified string.

Intern and IsInterned methods vary in their behavior. The Intern function will intern a string if it is not already interned, while IsInterned will not do so. When a string is not interned, IsInterned will return null.

Signature

Example

public static string IsInterned(String str)

Parameter

str: it is a string type parameter.

Return

It returns a reference.

C# String IsInterned Method Example

Example

using 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:

Output

Hello C#
Hello C#
Hello C#

C# String Intern vs IsInterned Example

Example

using 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:

Output

True
False

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience