การ Build และ Run โปรแกรม C# สามารถทำได้หลายวิธี ตั้งแต่ IDE เต็มรูปแบบจนถึง Command Line
วิธี 1: Visual Studio IDE (แนะนำสำหรับเริ่มต้น)
- เปิด Visual Studio → Create New Project → Console App
- เขียนโค้ดใน
Program.cs - กด F5 (Debug) หรือ Ctrl+F5 (Run Without Debugging)
วิธี 2: .NET CLI (Command Line) - Modern Way
# สร้างโปรเจกต์ใหม่ dotnet new console -n MyApp cd MyApp # Build dotnet build # Run dotnet run # Release Build dotnet publish -c Release
วิธี 3: คอมไพล์โดยตรงด้วย CSC (Legacy)
- สร้างไฟล์
helloworld.csใน Text Editor - เปิด Command Prompt / Terminal ไปที่โฟลเดอร์ไฟล์
- คอมไพล์:
csc helloworld.cs - สร้าง
helloworld.exe - รัน:
helloworld
// helloworld.cs
using System;
class Program { static void Main() { Console.WriteLine("Hello World"); } }
วิธี 4: Online Compilers
- dotnetfiddle.net
- Replit C#
- Try .NET (Microsoft)
- GitHub Codespaces / Gitpod
โครงสร้างไฟล์ Build Output
MyApp/ ├── bin/ │ └── Debug/ │ └── net8.0/ │ ├── MyApp.dll # Assembly (IL Code) │ ├── MyApp.exe # Executable (Windows) │ ├── MyApp.pdb # Debug Symbols │ └── MyApp.deps.json # Dependencies └── obj/ # Temporary Build Files
Target Frameworks
net8.0- .NET 8 (LTS, Cross-platform)net48- .NET Framework 4.8 (Windows Only)netstandard2.0- Library รองรับหลาย Platform
แนะนำ: ใช้ dotnet CLI สำหรับ CI/CD, Container, Cross-platform Development ใช้ Visual Studio / VS Code สำหรับ Development ปกติ