# พื้นฐาน C# (.NET) > ตัวแปรและค่าคงที่, ชนิดข้อมูลพื้นฐาน, control flow, class, struct, interface, exception - 25 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: .NET](https://sharpskill.dev/th/technologies/dotnet/interview-questions.md) ## 1. ตัวแปรใน C# คืออะไร? **คำตอบ** ตัวแปรคือพื้นที่จัดเก็บข้อมูลที่มีชื่อในหน่วยความจำ ซึ่งเก็บค่าที่สามารถเปลี่ยนแปลงได้ระหว่างการทำงานของโปรแกรม ตัวแปรแต่ละตัวมีชนิดข้อมูลที่กำหนดว่าสามารถเก็บค่าใดได้บ้างและสามารถทำการดำเนินการใดได้บ้าง การประกาศตัวแปรด้วยชนิดข้อมูลที่ชัดเจนช่วยให้ compiler ตรวจสอบความสอดคล้องของโค้ดและปรับการใช้หน่วยความจำให้เหมาะสมได้ ## 2. ความแตกต่างระหว่างตัวแปรและค่าคงที่ใน C# คืออะไร? **คำตอบ** ตัวแปรสามารถเปลี่ยนค่าได้หลังจากการกำหนดค่าเริ่มต้น ในขณะที่ค่าคงที่จะได้รับค่าในขณะคอมไพล์และคงที่ตลอดอายุการทำงานของโปรแกรม ค่าคงที่ถูกประกาศด้วยคีย์เวิร์ด const และต้องกำหนดค่าเริ่มต้นด้วยค่าที่ทราบในขณะคอมไพล์ การใช้ค่าคงที่สำหรับค่าที่ไม่เปลี่ยนแปลงช่วยให้อ่านง่ายขึ้นและเปิดโอกาสให้ compiler ปรับให้เหมาะสม ## 3. ชนิดข้อมูลใดที่เหมาะสำหรับเก็บจำนวนเต็มอย่างง่ายใน C#? **คำตอบ** ชนิด int เป็นชนิดจำนวนเต็มที่ใช้บ่อยที่สุดใน C# สำหรับเก็บจำนวนเต็ม โดยใช้พื้นที่ 32 บิตในหน่วยความจำและสามารถเก็บค่าได้ตั้งแต่ประมาณ -2 พันล้านถึง +2 พันล้าน สำหรับกรณีการใช้งานส่วนใหญ่ที่เกี่ยวข้องกับตัวนับ ดัชนี หรือปริมาณ int ให้ความสมดุลที่ดีระหว่างช่วงของค่าและประสิทธิภาพ ## มีอีก 22 คำถาม - ควรใช้ชนิดข้อมูลใดเพื่อเก็บค่าจริง/เท็จใน C#? - ไวยากรณ์ที่ถูกต้องสำหรับการประกาศค่าคงที่ใน C# คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ .NET อื่นๆ - [LINQ & Delegates](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-linq-delegates.md): 20 คำถาม, Junior - [พื้นฐานสำคัญของภาษา C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-language-essentials.md): 15 คำถาม, Junior - [พื้นฐาน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/aspnet-core-fundamentals.md): 18 คำถาม, Junior - [วงจรชีวิตของ request ใน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/aspnet-core-request-lifecycle.md): 20 คำถาม, Junior - [Configuration & Settings](https://sharpskill.dev/th/technologies/dotnet/interview-questions/configuration-settings.md): 20 คำถาม, Junior - [วงจรชีวิตของแอปพลิเคชัน](https://sharpskill.dev/th/technologies/dotnet/interview-questions/application-lifecycle.md): 20 คำถาม, Junior - [Dependency Injection](https://sharpskill.dev/th/technologies/dotnet/interview-questions/dependency-injection.md): 24 คำถาม, Mid-Level - [Entity Framework Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/entity-framework-core.md): 25 คำถาม, Mid-Level - [Minimal APIs](https://sharpskill.dev/th/technologies/dotnet/interview-questions/minimal-apis.md): 18 คำถาม, Mid-Level - [การพัฒนา Web API](https://sharpskill.dev/th/technologies/dotnet/interview-questions/web-api-development.md): 22 คำถาม, Mid-Level - [Async ใน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/async-aspnet-core.md): 20 คำถาม, Mid-Level - [Authentication & Authorization](https://sharpskill.dev/th/technologies/dotnet/interview-questions/authentication-authorization.md): 18 คำถาม, Mid-Level - [HttpClient & Networking](https://sharpskill.dev/th/technologies/dotnet/interview-questions/httpclient-networking.md): 20 คำถาม, Mid-Level - [การซีเรียลไลซ์ JSON](https://sharpskill.dev/th/technologies/dotnet/interview-questions/json-serialization.md): 20 คำถาม, Mid-Level - [Entity Framework Core ขั้นสูง](https://sharpskill.dev/th/technologies/dotnet/interview-questions/ef-core-advanced.md): 25 คำถาม, Mid-Level - [ฟีเจอร์ขั้นสูงของ C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-advanced-features.md): 20 คำถาม, Mid-Level - [Clean Architecture](https://sharpskill.dev/th/technologies/dotnet/interview-questions/clean-architecture.md): 20 คำถาม, Mid-Level - [Logging, Monitoring & Observability](https://sharpskill.dev/th/technologies/dotnet/interview-questions/logging-monitoring.md): 22 คำถาม, Mid-Level - [Unit Testing และ xUnit](https://sharpskill.dev/th/technologies/dotnet/interview-questions/unit-testing-xunit.md): 20 คำถาม, Mid-Level - [การทดสอบแบบบูรณาการ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/integration-testing.md): 18 คำถาม, Mid-Level - [Docker & Containerization](https://sharpskill.dev/th/technologies/dotnet/interview-questions/docker-containerization.md): 16 คำถาม, Mid-Level - [การจัดการแพ็กเกจ NuGet](https://sharpskill.dev/th/technologies/dotnet/interview-questions/nuget-package-management.md): 16 คำถาม, Mid-Level - [Memory Management & GC](https://sharpskill.dev/th/technologies/dotnet/interview-questions/memory-management-gc.md): 22 คำถาม, Senior - [การเขียนโปรแกรมแบบรีแอกทีฟ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/reactive-programming.md): 24 คำถาม, Senior - [Async/await และรูปแบบ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/async-await-patterns.md): 26 คำถาม, Senior - [.NET Design Patterns](https://sharpskill.dev/th/technologies/dotnet/interview-questions/dotnet-design-patterns.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/dotnet/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยและ Best Practices](https://sharpskill.dev/th/technologies/dotnet/interview-questions/security-best-practices.md): 24 คำถาม, Senior - [SignalR และเรียลไทม์](https://sharpskill.dev/th/technologies/dotnet/interview-questions/signalr-realtime.md): 22 คำถาม, Senior - [สถาปัตยกรรม Microservices](https://sharpskill.dev/th/technologies/dotnet/interview-questions/microservices-architecture.md): 25 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-basics