Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#
C#
  1. Obsolete Attributes ใน C# (ทำเครื่องหมาย Method ล้าสมัย)

    ถ้า Method มี Obsolete Attribute Compiler จะแจ้ง Warning (หรือ Error) หลัง Compile ใช้เมื่อมี Method ใหม่ แต่อยากเก็บ Method เก่าไว้ แจ้งให้ใช้ Method ใหม่แทน ตัวอย่าง using System; public class Demo { [Obsolete(Old Method shouldnt be used! Use New Method instead, true)] static void OldMeth

  2. Ternary Operator ใน C# (Conditional Operator)

    Ternary Operator (Conditional Operator) รับ 3 Arguments ประเมิน Boolean Expression Syntax: condition ? value_if_true : value_if_false ตัวอย่าง: y = (z == 1) ? 100 : 180; ถ้า z==1 จริง (True) y = 100 มิฉะนั้น y = 180 ตัวอย่างสมบูรณ์ 90 Console.WriteLine(Value of y = {0}, y);

  3. AddRange Method ใน C# List (เพิ่มหลายรายการพร้อมกัน)

    AddRange() เพิ่ม Collection ทั้งชุดเข้าไปใน List พร้อมกัน ตัวอย่าง สร้าง List และเพิ่มข้อมูล: List<int> list = new List<int>(); list.Add(100); list.Add(200); list.Add(300); list.Add(400); สร้าง Array ข้อมูลใหม่: int[] arr = new int[4] { 500, 600, 700, 800 }; ใช้ AddRange: list.AddRang

  4. Base Class สำหรับ Data Types ทั้งหมดใน C#.NET

    Object เป็น Base Class สำหรับ Data Types ทั้งหมดใน C# Object Type คือ Base Class สุดท้ายใน CTS (Common Type System) object เป็น Alias ของ System.Object Object Type = Boxing Value Type = Unboxing ตัวอย่าง using System; using System.IO; namespace Demo { class objectClass { public int x = 56; }

  5. การใช้ LINQ ใน C# (Language Integrated Query)

    LINQ (Language Integrated Query) เป็น Component ของ .NET Framework และ Query Syntax มาตรฐานใน C# มี Method Names ชุดหนึ่ง และขยายภาษาด้วย Query Expressions ใช้ LINQ ด้วย: using System.Linq; ตัวอย่าง: Count และ Average using System; using System.Linq; class Demo { static void Main() {

  6. การใช้ LINQ เรียงลำดับ List ใน C#

    ใช้ LINQ orderby keyword เรียง List ใน C# ตัวอย่าง: เรียงตามความยาว String var myLen = from element in myList orderby element.Length select element; ตัวอย่างสมบูรณ์ using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List<string>

  7. การใช้ NameValueCollection Class ใน C#

    NameValueCollection เก็บ Value หลายค่าได้สำหรับ Key เดียว การใช้งาน สร้าง Collection: static NameValueCollection GetCollection() { NameValueCollection myCollection = new NameValueCollection(); myCollection.Add(Tim, One); myCollection.Add(John, Two); myCollection.Add(Jamie, Three);

  8. Finalizers ใน C# (ตัวทำลายออบเจกต์)

    Finalizers ใน C# ใช้ทำลาย Instance ของ Class (Destruct) และปล่อย Resources ข้อสำคัญของ Finalizers Class หนึ่งมี Finalizer ได้เพียง 1 ตัว ไม่สามารถ Inherit หรือ Overload Finalizers ได้ Finalizer ไม่มี Parameters Finalizers เรียกใช้งานอัตโนมัติ (โดย Garbage Collector) Finalizers ประกาศคล้าย Destruct

  9. Predefined Attributes ใน C# (Attributes ที่มีอยู่สำเร็จ)

    Predefined Attributes ใน C# มี 3 ตัว: AttributeUsage Conditional Obsolete AttributeUsage อธิบายว่า Custom Attribute Class ใช้ได้อย่างไร Syntax: [AttributeUsage(validon, AllowMultiple = allowmultiple, Inherited = inherited)] Conditional Mark Method ว่า Conditional Execution ขึ้นอยู่กับ Preprocessin

  10. โครงสร้างพื้นฐานของโปรแกรม C#

    ตัวอย่างโปรแกรม C# ง่ายๆ using System; namespace DemoApplication { class HelloWorld { static void Main(string[] args) { Console.WriteLine(Welcome!); Console.ReadKey(); } } } องค์ประกอบหลัก using using System; - นำเข้า Namespace System โปรแ

  11. Reflections ใน C# (การสะท้อน/ตรวจสอบข้อมูล Type Runtime)

    Reflection Objects ใช้ดึงข้อมูล Type ในขณะ Runtime คลาสต่างๆ อยู่ใน Namespace System.Reflection Object MemberInfo ต้อง Initialize ก่อนเพื่อค้นหา Attributes ของ Class System.Reflection.MemberInfo info = typeof(MyClass); ตัวอย่าง using System; using System.Reflection; [AttributeUsage(AttributeTargets

  12. Reference Data Types ใน C#

    Reference Data Type ไม่เก็บข้อมูลจริง แต่เก็บ Reference (ที่อยู่) ของตัวแปร Built-in Reference Types ใน C#: 1. Object Type Base Class สุดท้ายของทุก Data Types ใน CTS กำหนดค่าได้ทุกประเภท (Value, Reference, Predefined, User-defined) object ob; ob = 250; // Boxing 2. Dynamic Type เก็บค่า Type ใดก็ได้

  13. Jagged Arrays ใน C# คืออะไร

    Jagged Array คือ Array ของ Arrays ใน C# สามารถประกาศและ Initialize ได้: int[][] rank = new int[1][]{new int[]{5,3,1}}; ตัวอย่าง using System; namespace Program { class Demo { static void Main(string[] args) { int[][] rank = new int[][]{new int[]{1,2},new int[]{3,

  14. Base Class สำหรับ Exceptions ทั้งหมดใน C#

    System.SystemException เป็น Base Class สำหรับ Predefined System Exceptions คลาสที่สืบทอดจาก System.Exception ได้แก่ System.ApplicationException และ System.SystemException System.ApplicationException รองรับ Exceptions ที่โปรแกรมเมอร์สร้างเอง ควรสืบทอดจากคลาสนี้ Exceptions ภายใต้ System.SystemExceptio

  15. Try-Catch-Finally ใน C# (การจัดการข้อยกเว้น)

    C# Exception Handling ใช้ Keywords: try, catch, finally try - บล็อกที่อาจเกิด Exception catch - จับและจัดการ Exception finally - รันเสมอ ไม่ว่าจะมี Exception หรือไม่ ตัวอย่าง: การหารด้วยศูนย์ using System; namespace ErrorHandlingApplication { class DivNumbers { int result;

  16. Substring ใน C# (ดึงส่วนของสตริง)

    Substring() ใช้ดึงส่วนย่อยของ String ใน C# ตัวอย่างตรวจสอบว่า String มีตัวอักษรซ้ำหรือไม่: ตัวอย่าง using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Demo { public bool CheckUnique(string str) { string on

  17. Streams ใน C# (การทำงานกับสตรีม)

    Stream คือลำดับของ Bytes ที่ผ่าน Communication Path มี 2 สตรีมหลัก: Input Stream - อ่านข้อมูลจากไฟล์ (Read Operation) Output Stream - เขียนข้อมูลลงไฟล์ (Write Operation) คลาส FileStream ใน System.IO ช่วย Read/Write/Close ไฟล์ สืบทอดมาจาก Abstract Class Stream Syntax สร้าง FileStream FileStream <

  18. Volatile Keyword ใน C#

    ใช้ volatile keyword เพื่อลดปัญหา Concurrency (Race Conditions) ใน C# ตัวอย่าง: Volatile Field class Program { public volatile int a; public void Program(int _a) { a = _a; } } ตัวอย่าง: ใช้กับ Static Variables และ Thread static string _out; static volatile bool _new; void volatileFunc() {

  19. IDE ที่ดีที่สุดสำหรับ C# บน MacOS

    บน Windows ใช้ Visual Studio บน MacOS IDE ที่ดีที่สุดคือ MonoDevelop (รู้จักว่า Xamarin Studio) Open Source รัน C# ได้หลาย Platform: Windows, Linux, macOS สำหรับ Mac มีเวอร์ชันพิเศษชื่อ Visual Studio for Mac มีฟีเจอร์คล้าย VS Windows: IntelliSense, Refactoring Tools คุณสมบัติ MonoDevelop Multi-plat

  20. Try/Catch/Finally/Throw Keywords ใน C#

    Exception Handling ใน C# ใช้ Keywords 4 ตัว: try - บล็อกโค้ดที่อาจเกิด Exception ตามด้วย Catch Blocks catch - จับ Exception ที่เกิดขึ้น จัดการ Error finally - บล็อกที่รันเสมอ ไม่ว่าจะมี Exception หรือไม่ (เช่น ปิดไฟล์) throw - โยน Exception เมื่อพบปัญหา Syntax try { // statements causing excep

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:21/134  20-คอมพิวเตอร์/Page Goto:1 15 16 17 18 19 20 21 22 23 24 25 26 27