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

Literals ใน C# (ค่าคงที่)

Literals คือค่าคงที่ (Fixed Values) ที่โปรแกรมไม่เปลี่ยนแปลงระหว่างรัน Constants มีได้ทุก Basic Data Types

1. Integer Literals

Decimal หรือ Hexadecimal (Prefix 0x/0X)

20    // int
30u   // unsigned int
30l   // long

2. Float Literals

มี Integer Part, Decimal Point, Fractional Part, Exponent Part

2.64734
314159E-5F

3. String Literals

ล้อมรอบด้วย Double Quotes "" หรือ @"" มี Escape Sequences ได้

"Hello, World"
"Welcome, \"

ยังมี Enumeration Constants อีกด้วย