Information Technology Reference
In-Depth Information
For example, the following code compares some regular and verbatim string literals:
string rst1 = "Hi there!";
string vst1 = @"Hi there!";
string rst2 = "It started, \"Four score and seven...\"";
string vst2 = @"It started, ""Four score and seven...""";
string rst3 = "Value 1 \t 5, Val2 \t 10"; // Interprets tab esc sequence
string vst3 = @"Value 1 \t 5, Val2 \t 10"; // Does not interpret tab
string rst4 = "C:\\Program Files\\Microsoft\\";
string vst4 = @"C:\Program Files\Microsoft\";
string rst5 = " Print \x000A Multiple \u000A Lines";
string vst5 = @" Print
Multiple
Lines";
Printing these strings produces the following output:
Hi there!
Hi there!
It started, "Four score and seven..."
It started, "Four score and seven..."
Value 1 5, Val2 10
Value 1 \t 5, Val2 \t 10
C:\Program Files\Microsoft\
C:\Program Files\Microsoft\
Print
Multiple
Lines
Print
Multiple
Lines
Note The compiler saves memory by having identical string literals share the same memory location in
the heap.
Search WWH ::




Custom Search