String intern
In this chapter you will learn:
Intern a string
using System;// j a v a 2 s . c o m
using System.Text;
class Main
{
static void Main(string[] args)
{
string sLiteral = "Automatically Interned java2s.com";
string sNotInterned = "Not " + sLiteral;
TestInterned( sLiteral );
TestInterned( sNotInterned );
String.Intern( sNotInterned );
TestInterned( sNotInterned );
string string1 = "";
String string2 = "";
string1 = "asdf";
string2 = "asdf1";
}
static void TestInterned( string str )
{
if( String.IsInterned( str ) != null )
{
Console.WriteLine( "The string \"{0}\" is interned.", str );
}
else
{
Console.WriteLine( "The string \"{0}\" is not interned.", str );
}
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » String