C# 中的字符常量与字符串文字
csharpprogrammingserver side programming更新于 2024/9/12 5:09:00
字符常量
字符文字用单引号括起来。例如,'x' 可以存储在 char 类型的简单变量中。字符文字可以是普通字符(例如 'x')、转义序列(例如 '\t')或通用字符(例如 '\u02C0')。
C# 中的某些字符前面带有反斜杠。它们具有特殊含义,用于表示换行符 (
) 或制表符 (\t)。
示例
using System; namespace Demo { class MyApplication { static void Main(string[] args) { Console.WriteLine("Welcome\t to the website
"); Console.ReadLine(); } } }
输出
Welcome to the website
字符串文字
字符串文字或常量用双引号"" 或 @"" 括起来。字符串包含与字符文字类似的字符:普通字符、转义序列和通用字符。