X hits on this document

906 views

0 shares

0 downloads

0 comments

57 / 396

C# LANGUAGE SPECIFICATION

regular-string-literal-characters: regular-string-literal-character regular-string-literal-characters   regular-string-literal-character

regular-string-literal-character: single-regular-string-literal-character simple-escape-sequence hexadecimal-escape-sequence unicode-escape-sequence

single-regular-string-literal-character: Any character except " (U+0022), \ (U+005C), and new-line-character

verbatim-string-literal: @"   verbatim -string-literal-charactersopt   "

verbatim-string-literal-characters: verbatim-string-literal-character verbatim-string-literal-characters   verbatim-string-literal-character

verbatim-string-literal-character: single-verbatim-string-literal-character quote-escape-sequence

single-verbatim-string-literal-character: Any character except "

quote-escape-sequence: ""

A character that follows a backslash character (\) in a regular-string-literal-character must be one of the following characters: ', ", \, 0, a, b, f, n, r, t, u, U, x, v. Otherwise, a compile-time error occurs.

The example

string a = "hello, world";// hello, world string b = @"hello, world";// hello, world

string c = "hello \t world";// hello world string d = @"hello \t world";// hello \t world

string e = "Joe said \"Hello\" to me";// Joe said "Hello" to me string f = @"Joe said ""Hello"" to me";// Joe said "Hello" to me

string g = "\\\\server\\share\\file.txt";// \\server\share\file.txt string h = @"\\server\share\file.txt";// \\server\share\file.txt

string i = "one\r\ntwo\r\nthree"; string j = @"one two three";

shows a variety of string literals. The last string literal, j, is a verbatim string literal that spans multiple lines. The characters between the quotation marks, including white space such as new line characters, are preserved verbatim.

Since a hexadecimal escape sequence can have a variable number of hex digits, the string literal "\x123" contains a single character with hex value 123. To create a string containing the character with hex value 12 followed by the character 3, one could write "\x00123" or "\x12" + "3" instead.

The type of a string-literal is string.

44Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views906
Page views906
Page last viewedTue Dec 06 20:39:52 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments