分享
 
 
 

9.4.4.5 String literals

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

9.4.4.5 String literals

C# supports two forms of string literals: regular string literals and

verbatim string literals. A regular string

literal consists of zero or more characters enclosed in double quotes, as

in "hello, world", and may include

both simple escape sequences (such as \t for the tab character), and

hexadecimal and Unicode escape sequences.

A verbatim string literal consists of an @ character followed by a

double-quote character, zero or more characters,

and a closing double-quote character. [Example: A simple example is

@"hello, world". end example] In a

verbatim string literal, the characters between the delimiters are

interpreted verbatim, with the only exception

being a quote-escape-sequence. In particular, simple escape sequences, and

hexadecimal and Unicode escape

sequences are not processed in verbatim string literals. A verbatim string

literal may span multiple lines.

string-literal::

regular-string-literal

verbatim-string-literal

regular-string-literal::

" regular-string-literal-charactersopt "

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 "

Chapter 9 Lexical structure

61

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::

""

[Note: 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. end note]

[Example: The example

string a = "Happy birthday, Joel"; // Happy birthday, Joel

string b = @"Happy birthday, Joel"; // Happy birthday, Joel

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. end example]

[Note: 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. end note]

The type of a string-literal is string.

Each string literal does not necessarily result in a new string instance.

When two or more string literals that are

equivalent according to the string equality operator (§14.9.7), appear in

the same assembly, these string literals

refer to the same string instance. [Example: For instance, the output

produced by

class Test

{

static void Main() {

object a = "hello";

object b = "hello";

System.Console.WriteLine(a == b);

}

}

is True because the two literals refer to the same string instance. end

example]

9.4.4.6 The null literal

null-literal::

null

The type of a null-literal is the null type.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有