Csharp/C Sharp/Data Types/Literal

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

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) );
    }
}