官术网_书友最值得收藏!

String

A string is a sequence of characters. In C#, a string is represented by double quotation marks. There are different ways a string can be created in C#. Let's look at the different ways of creating a string in C#:

string s = "hello world";
string s1 = "hello \n\r world"; //prints the string with escape sequence
string s2 = @"hello \n\r world"; //prints the string without escape sequence
string s3 = $"S1 : {s1}, S2: {s2}"; // Replaces the {s1} and {s2} with values

The @ character can be placed as a prefix before a string to take the string as it is, without worrying about any escape characters. It is called a verbatim string. The $ character is used as a prefix for string interpolation. In case your string literal is preceded with the $ sign, the variables are automatically replaced with values if they're placed within { } brackets.

主站蜘蛛池模板: 北宁市| 龙山县| 凉山| 瓦房店市| 饶阳县| 闽侯县| 车险| 明水县| 三亚市| 江口县| 房山区| 邮箱| 星座| 五寨县| 义乌市| 泰州市| 冷水江市| 武汉市| 佛山市| 红安县| 大理市| 精河县| 平利县| 马关县| 永嘉县| 六安市| 泰和县| 黔南| 江达县| 清流县| 靖州| 江口县| 曲阜市| 本溪市| 剑阁县| 留坝县| 运城市| 沙坪坝区| 东阳市| 平武县| 彰化县|