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

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.

主站蜘蛛池模板: 镇雄县| 抚宁县| 东港市| 定南县| 贵南县| 庆云县| 宁海县| 五峰| 苍山县| 元谋县| 新沂市| 陆川县| 盐山县| 大足县| 西林县| 延津县| 双牌县| 新龙县| 永清县| 晋城| 巨鹿县| 抚远县| 汝州市| 凌云县| 东阿县| 肇源县| 湟中县| 阜新| 裕民县| 肇东市| 车险| 邮箱| 师宗县| 梁平县| 利辛县| 松桃| 丹凤县| 洱源县| 西华县| 灌南县| 崇左市|