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

คำต่อท้ายตัวพิมพ์เล็กใน C#

C# อนุญาตให้ใช้ Suffix ตัวพิมพ์เล็ก (l, f, d, m, u) ได้ แต่ ไม่แนะนำ เพราะอาจสับสนกับตัวเลข (โดยเฉพาะ l กับ 1)

ตัวอย่าง

using System;

public class Program
{
    public static void Main()
    {
        long a = 29876l;   // Warning: 'l' suffix easily confused with '1'
        float b = 95.10f;  // OK แต่ควรใช้ F
        Console.WriteLine(a);
        Console.WriteLine(b);
    }
}

ผลลัพธ์

29876
95.1

คำเตือนจาก Compiler: "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)"