- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 159字
- 2021-07-02 12:44:35
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.
推薦閱讀
- Java入門經(jīng)典(第6版)
- 程序設(shè)計與實踐(VB.NET)
- 測試驅(qū)動開發(fā):入門、實戰(zhàn)與進階
- Oracle Exadata性能優(yōu)化
- 碼上行動:零基礎(chǔ)學(xué)會Python編程(ChatGPT版)
- JavaScript by Example
- QTP自動化測試進階
- 重學(xué)Java設(shè)計模式
- Getting Started with NativeScript
- Java:High-Performance Apps with Java 9
- C# 8.0核心技術(shù)指南(原書第8版)
- 詳解MATLAB圖形繪制技術(shù)
- 響應(yīng)式Web設(shè)計:HTML5和CSS3實戰(zhàn)(第2版)
- Django 3.0入門與實踐
- C++ Fundamentals