Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

Tokens ใน C# คืออะไร

Token คือองค์ประกอบเล็กที่สุดของโปรแกรม มาดู Identifiers และ Keywords ที่เป็น Tokens ใน C#

Keywords (คำสงวน)

Keywords เป็นคำสงวนที่ Compiler รู้จัก ไม่สามารถใช้เป็น Identifier ได้ ยกเว้นจะเติม @ นำหน้า

ตัวอย่าง Keywords ใน C#:

abstractasbaseboolbreakbytecase
catchcharcheckedclassconstcontinuedecimal
defaultdelegatedodoubleelseenumevent
explicitexternfalsefinallyfixedfloatfor
foreachgotoifimplicitinin (generic)int
interfaceinternalislocklongnamespacenew
nullobjectoperatoroutout (generic)overrideparams

Identifiers (ตัวระบุชื่อ)

Identifier คือชื่อที่ใช้ระบุ Class, Variable, Function หรือ Item ที่ผู้ใช้สร้าง กฎการตั้งชื่อ:

  • ขึ้นต้นด้วยตัวอักษร ตามด้วยตัวอักษร, ตัวเลข (0-9) หรือ Underscore (_) ตัวแรกไม่สามารถเป็นตัวเลขได้
  • ไม่得有ช่องว่างหรือสัญลักษณ์ ? - + ! @ # % ^ & * ( ) [ ] { } . ; : " ' / \ แต่ Underscore (_) ใช้ได้