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

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

Comments (คอมเมนต์) ใช้สำหรับอธิบายโค้ด คอมไพเลอร์จะไม่สนใจส่วนของคอมเมนต์ คอมเมนต์หลายบรรทัดใน C# เริ่มต้นด้วย /* และจบด้วย */

Multi-line Comments (คอมเมนต์หลายบรรทัด)

/* The following is a mult-line comment In C# /*

ส่วน /*...*/ จะถูกคอมไพเลอร์เพิกเฉย ใช้เพื่อเพิ่มคอมเมนต์ในโปรแกรม

Single-line Comments (คอมเมนต์บรรทัดเดียว)

// variable int a = 10;

ตัวอย่างโปรแกรม C# แสดงการใช้คอมเมนต์

using System; 
namespace Demo { 
    class Program { 
        static void Main(string[] args) { 
            /* I have started learning C# and 
            is my first program */ 
            // displaying text 
            Console.WriteLine("Hello World"); 
            Console.ReadKey(); 
        } 
    } 
}

ผลลัพธ์

Hello World