Character Literal ล้อมรอบด้วย Single Quote เช่น 'x' เก็บในตัวแปร char ได้ 3 รูปแบบ:
- Plain character:
'x','A','9' - Escape sequence:
'\t'(Tab),'\n'(Newline),'\\'(Backslash) - Unicode character:
'\u02C0'
ตัวอย่าง: Escape Sequences
using System;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome!\t\n\n"); // Tab + 2 Newlines
Console.WriteLine("This is it!");
Console.ReadLine();
}
}
}
Escape Sequences พบบ่อย
| Sequence | ความหมาย |
|---|---|
| \' | Single quote |
| \" | Double quote |
| \\ | Backslash |
| \n | New line |
| \t | Horizontal tab |
| \r | Carriage return |
| \uXXXX | Unicode character (4 hex digits) |