String.IsInterned メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim str As String Dim returnValue As String returnValue = String.IsInterned(str)
戻り値
str が共通言語ランタイムの "インターン プール" 内にある場合は、str への String 参照。それ以外の場合は null 参照 (Visual Basic では Nothing)。


共通言語ランタイムは、"インターン プール" と呼ばれるテーブルを自動的に管理します。このテーブルには、プログラムで宣言された各リテラル文字列定数の単一インスタンスと、プログラムを使用して追加した String の一意のインスタンスが格納されています。
インターン プールでは、文字列の格納域が維持されます。リテラル文字列定数を複数の変数に割り当てると、各変数が、同一値を持つ異なる String インスタンスではなく、インターン プールの同一定数を参照するように設定されます。
このメソッドは、インターン プールで str を検索します。str が既に確保されている場合は、そのインスタンスへの参照が返されます。それ以外の場合は null 参照 (Visual Basic では Nothing) が返されます。

次のコード例では、リテラル文字列がコンパイラによって自動的にインターン プールに格納されるようすをデモンストレーションしています。
' Sample for String.IsInterned(String) Imports System Imports System.Text Class Sample Public Shared Sub Main() ' String str1 is known at compile time, and is automatically interned. Dim str1 As [String] = "abcd" ' Constructed string, str2, is not explicitly or automatically interned. Dim str2 As [String] = New StringBuilder().Append("wx").Append("yz").ToString() Console.WriteLine() Test(1, str1) Test(2, str2) End Sub 'Main Public Shared Sub Test(sequence As Integer, str As [String]) Console.Write("{0}) The string, '", sequence) Dim strInterned As [String] = [String].IsInterned(str) If strInterned Is Nothing Then Console.WriteLine("{0}', is not interned.", str) Else Console.WriteLine("{0}', is interned.", strInterned) End If End Sub 'Test End Class 'Sample ' 'This example produces the following results: ' '1) The string, 'abcd', is interned. '2) The string, 'wxyz', is not interned. '
// Sample for String.IsInterned(String) using System; using System.Text; class Sample { public static void Main() { // String str1 is known at compile time, and is automatically interned. String str1 = "abcd"; // Constructed string, str2, is not explicitly or automatically interned. String str2 = new StringBuilder().Append("wx").Append("yz").ToString(); Console.WriteLine(); Test(1, str1); Test(2, str2); } public static void Test(int sequence, String str) { Console.Write("{0}) The string, '", sequence); String strInterned = String.IsInterned(str); if (strInterned == null) Console.WriteLine("{0}', is not interned.", str); else Console.WriteLine("{0}', is interned.", strInterned); } } /* This example produces the following results: 1) The string, 'abcd', is interned. 2) The string, 'wxyz', is not interned. */
// Sample for String::IsInterned(String) using namespace System; using namespace System::Text; void Test( int sequence, String^ str ) { Console::Write( "{0} The string '", sequence ); String^ strInterned = String::IsInterned( str ); if ( strInterned == nullptr ) Console::WriteLine( "{0}' is not interned.", str ); else Console::WriteLine( "{0}' is interned.", strInterned ); } int main() { // String str1 is known at compile time, and is automatically interned. String^ str1 = "abcd"; // Constructed string, str2, is not explicitly or automatically interned. String^ str2 = (gcnew StringBuilder)->Append( "wx" )->Append( "yz" )->ToString(); Console::WriteLine(); Test( 1, str1 ); Test( 2, str2 ); } /* This example produces the following results: 1) The string 'abcd' is interned. 2) The string 'wxyz' is not interned. */
// Sample for String.IsInterned(String) import System.*; import System.Text.*; class Sample { public static void main(String[] args) { // String str1 is known at compile time, and is automatically interned. String str1 = "abcd"; // Constructed string, str2, is not explicitly or automatically // interned. String str2 = (new StringBuilder()).Append("wx").Append("yz"). ToString(); Console.WriteLine(); Test(1, str1); Test(2, str2); } //main public static void Test(int sequence, String str) { Console.Write("{0}) The string, '", System.Convert.ToString(sequence)); String strInterned = String.IsInterned(str); if (strInterned == null) { Console.WriteLine("{0}', is not interned.", str); } else { Console.WriteLine("{0}', is interned.", strInterned); } } //Test } //Sample /* This example produces the following results: 1) The string, 'abcd', is interned. 2) The string, 'wxyz', is not interned. */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からString.IsInterned メソッドを検索する場合は、下記のリンクをクリックしてください。

- String.IsInterned メソッドのページへのリンク