Token คือองค์ประกอบเล็กที่สุดของโปรแกรม มาดู Identifiers และ Keywords ที่เป็น Tokens ใน C#
Keywords (คำสงวน)
Keywords เป็นคำสงวนที่ Compiler รู้จัก ไม่สามารถใช้เป็น Identifier ได้ ยกเว้นจะเติม @ นำหน้า
ตัวอย่าง Keywords ใน C#:
| abstract | as | base | bool | break | byte | case |
| catch | char | checked | class | const | continue | decimal |
| default | delegate | do | double | else | enum | event |
| explicit | extern | false | finally | fixed | float | for |
| foreach | goto | if | implicit | in | in (generic) | int |
| interface | internal | is | lock | long | namespace | new |
| null | object | operator | out | out (generic) | override | params |
Identifiers (ตัวระบุชื่อ)
Identifier คือชื่อที่ใช้ระบุ Class, Variable, Function หรือ Item ที่ผู้ใช้สร้าง กฎการตั้งชื่อ:
- ขึ้นต้นด้วยตัวอักษร ตามด้วยตัวอักษร, ตัวเลข (0-9) หรือ Underscore (_) ตัวแรกไม่สามารถเป็นตัวเลขได้
- ไม่得有ช่องว่างหรือสัญลักษณ์ ? - + ! @ # % ^ & * ( ) [ ] { } . ; : " ' / \ แต่ Underscore (_) ใช้ได้