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

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.

主站蜘蛛池模板: 白山市| 普定县| 黄冈市| 申扎县| 张家界市| 蓬溪县| 漳平市| 台湾省| 施秉县| 开封市| 宁河县| 紫阳县| 肇州县| 广水市| 襄垣县| 兴义市| 阿瓦提县| 云安县| 巴彦淖尔市| 青龙| 霞浦县| 新郑市| 沧源| 徐闻县| 上高县| 泸定县| 台中市| 洛南县| 周至县| 民乐县| 营口市| 盱眙县| 高安市| 辉县市| 广元市| 巨野县| 东乌珠穆沁旗| 北川| 平塘县| 利辛县| 望江县|