- 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.
推薦閱讀
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- HTML5 移動Web開發從入門到精通(微課精編版)
- C語言從入門到精通(第4版)
- Java軟件開發基礎
- 精通網絡視頻核心開發技術
- Python編程與幾何圖形
- Hands-On Swift 5 Microservices Development
- 算法訓練營:提高篇(全彩版)
- INSTANT Django 1.5 Application Development Starter
- Python算法指南:程序員經典算法分析與實現
- Unity 2D Game Development Cookbook
- MySQL從入門到精通(軟件開發視頻大講堂)
- HTML 5與CSS 3權威指南(第3版·上冊)
- C++ Application Development with Code:Blocks
- Python網絡爬蟲實例教程(視頻講解版)