Csharp/C Sharp/Data Types/Literal
Версия от 15:31, 26 мая 2010; (обсуждение)
Creating a literal
using System;
class Test {
public static void Main() {
// Create a simple string literal
string s1 = "This is a test";
// Create a string literal with an escaped character
string s2 = "This is a \"real\" test";
// Create a string literal with the @ sign
string s3 = @"This is a \real\ test";
// Output them
Console.WriteLine("String 1 = {0}", s1 );
Console.WriteLine("String 2 = {0}", s2 );
Console.WriteLine("String 3 = {0}", s3 );
}
}
String literals
using System;
public class EntryPoint
{
static void Main( string[] args ) {
string lit1 = "c:\\windows\\system32";
string lit2 = @"c:\windows\system32";
string lit3 = @"
line one
line two
";
Console.WriteLine( lit3 );
Console.WriteLine( "Object.RefEq(lit1, lit2): {0}",
Object.ReferenceEquals(lit1, lit2) );
}
}