调试lucene.NET时候遇到的,希望对大家有用。
-------------
更新: 2008 年 7 月
命名空间: System
程序集: mscorlib(在 mscorlib.dll 中)
语法
| Visual Basic(声明) |
Public Shared Function Intern ( _
str As String _
) As String
|
| Visual Basic (用法) |
Dim str As String
Dim returnValue As String
returnValue = String.Intern(str)
|
| JScript |
public static function Intern(
str : String
) : String
|
异常
备注
示例
下面的代码示例使用三个值相等的字符串确定新建的字符串和留用的字符串是否相等。
| Visual Basic |
复制代码 |
Imports System
Imports System.Text
Class Sample
Public Shared Sub Main()
Dim s1 As [String] = "MyTest"
Dim s2 As [String] = New StringBuilder().Append("My").Append("Test").ToString()
Dim s3 As [String] = [String].Intern(s2)
Console.WriteLine("s1 = '{0}'", s1)
Console.WriteLine("s2 = '{0}'", s2)
Console.WriteLine("s3 = '{0}'", s3)
Console.WriteLine("Is s2 the same reference as s1?: {0}", s2 Is s1)
Console.WriteLine("Is s3 the same reference as s1?: {0}", s3 Is s1)
End Sub 'Main
End Class 'Sample
|
| C# |
复制代码 |
using System;
using System.Text;
class Sample {
public static void Main() {
String s1 = "MyTest";
String s2 = new StringBuilder().Append("My").Append("Test").ToString();
String s3 = String.Intern(s2);
Console.WriteLine("s1 == '{0}'", s1);
Console.WriteLine("s2 == '{0}'", s2);
Console.WriteLine("s3 == '{0}'", s3);
Console.WriteLine("Is s2 the same reference as s1?: {0}", (Object)s2==(Object)s1);
Console.WriteLine("Is s3 the same reference as s1?: {0}", (Object)s3==(Object)s1);
}
}
|
| Visual C++ |
复制代码 |
using namespace System;
using namespace System::Text;
int main()
{
String^ s1 = "MyTest";
String^ s2 = (gcnew StringBuilder)->Append( "My" )->Append( "Test" )->ToString();
String^ s3 = String::Intern( s2 );
Console::WriteLine( "s1 == '{0}'", s1 );
Console::WriteLine( "s2 == '{0}'", s2 );
Console::WriteLine( "s3 == '{0}'", s3 );
Console::WriteLine( "Is s2 the same reference as s1?: {0}", s2 == s1 );
Console::WriteLine( "Is s3 the same reference as s1?: {0}", s3 == s1 );
}
|
| J# |
复制代码 |
// Sample for String.Intern(String)
import System.*;
import System.Text.*;
class Sample
{
public static void main(String[] args)
{
String s1 = "MyTest";
String s2 = (new StringBuilder()).Append("My").Append("Test").ToString();
String s3 = String.Intern(s2);
Console.WriteLine("s1 == '{0}'", s1);
Console.WriteLine("s2 == '{0}'", s2);
Console.WriteLine("s3 == '{0}'", s3);
Console.WriteLine("Is s2 the same reference as s1?: {0}",
System.Convert.ToString((Object)s2 == (Object)s1));
Console.WriteLine("Is s3 the same reference as s1?: {0}",
System.Convert.ToString((Object)s3 == (Object)s1));
} //main
} //Sample
/*
This example produces the following results:
s1 == 'MyTest'
s2 == 'MyTest'
s3 == 'MyTest'
Is s2 the same reference as s1?: False
Is s3 the same reference as s1?: True
*/
|
平台
版本信息
.NET Framework
受以下版本支持:3.5、3.0、2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:3.5、2.0、1.0
XNA Framework
受以下版本支持:2.0、1.0
另请参见
修订记录
|
日期
|
修订
|
原因
|
|
2008 年 7 月
|
在“版本注意事项”部分中增加了对 .NET Framework 3.5 SP1 中的方法行为的讨论。
|
内容 Bug 修复
|