Mono Class Library: System.String Overview | Members

System.String.IsInterned Method

Retrieves a reference to a specified string. [Edit]

public static string IsInterned (string str)

Parameters

str
A string. [Edit]

Returns

A string reference to str if it is in the system's intern pool; otherwise, a null reference. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionstr is a null reference. [Edit]

Remarks

Instances of each unique literal string constant declared in a program, as well as any unique instance of string you add programmatically are kept in a table, called the "intern pool".

The intern pool conserves string storage. If a literal string constant is assigned to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of string that have identical values.

Note: This method does not return a bool value, but can still be used where a bool is needed.

[Edit]

Example

The following example demonstrates the string.IsInterned(string) method.

C# Example
using System;
using System.Text;

public class StringExample {
    public static void Main() {

        String s1 = new StringBuilder().Append("My").Append("Test").ToString(); 

        Console.WriteLine(String.IsInterned(s1) != null);
    }
}

The output is

True

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0