Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#
C#
  1. Key-based I/O Collections ใน C# คืออะไร

    Key-based I/O Collections ใน C# คือ SortedList<TKey, TValue> - คอลเลกชัน Key-Value ที่จัดเรียงตาม Key อัตโนมัติ เข้าถึงได้ทั้ง Key และ Index การเพิ่มข้อมูล SortedList<string, string> s = new SortedList<string, string>(); s.Add(Sub1, Physics); s.Add(Sub2, Chemistry); s.Add(Sub3, Bi

  2. Identifiers (ตัวระบุชื่อ) ใน C# คืออะไร

    Identifier คือชื่อที่ใช้ระบุ Class, Variable, Method, หรือ User-defined Item อื่นๆ กฎการตั้งชื่อ (Naming Rules) ขึ้นต้นด้วย ตัวอักษร (Letter) หรือ Underscore (_) - ไม่ใช่ตัวเลข ตามด้วย ตัวอักษร, ตัวเลข (0-9), หรือ Underscore (_) ได้ ไม่มี Space หรือ Special Characters: ? - + ! @ # % ^ & * ( )

  3. Nullable Data Types ใน C# คืออะไร

    Nullable Types อนุญาตให้ Value Type (ปกติไม่สามารถเป็น null ได้) รับค่า null ได้ โดยใช้ ? Suffix หรือ Nullable<T> Syntax int? num1 = null; // Skipped syntax Nullable<int> num2 = null; // Full syntax ตัวอย่างครบถ้วน using System; namespace Demo { class Program {

  4. Dynamic Data Types ใน C# คืออะไร

    Dynamic Type (C# 4.0+) เก็บค่าได้ทุกชนิด Type Checking เกิดขึ้นที่ Runtime (ไม่ใช่ Compile-time) Syntax dynamic variableName = value; ตัวอย่าง using System; class Program { static void Main() { dynamic val1 = 100; // int dynamic val2 = Hello; // string dynami

  5. Overloaded Indexers ใน C# คืออะไร

    Indexer ทำให้ออบเจกต์เข้าถึงได้เหมือน Array ด้วย [] สามารถ Overload ได้หลายรูปแบบ (พารามิเตอร์ต่างชนิด/จำนวน) ตัวอย่าง: Indexer หลายรูปแบบ using System; namespace IndexerApplication { class IndexedNames { private string[] namelist = new string[10]; static public int Size =

  6. Literals (ค่าคงที่) ใน C#

    Literals คือค่าคงที่ที่เขียนตรงในโค้ด ไม่เปลี่ยนแปลงระหว่างรันโปรแกรม Integer Literals ฐาน 10 (Decimal): 20, -30, 0 ฐาน 16 (Hexadecimal): 0xFF, 0X1A (Prefix 0x หรือ 0X) Suffix: U/u (unsigned), L/l (long), UL/ul (unsigned long) 20 // int 30U // uint 30L // long 30UL // ulong

  7. String Title Case ใน C# คืออะไร

    Title Case คือการทำให้ตัวอักษรแรกของแต่ละคำเป็นตัวพิมพ์ใหญ่ (Capitalize) ใช้เมธอด TextInfo.ToTitleCase() ตัวอย่าง using System; using System.Globalization; class Demo { static void Main() { string str = jack sparrow; // ใช้ CultureInfo ปัจจุบัน string resul

  8. Lambda Expressions ใน C# คืออะไร

    Lambda Expression คือ ฟังก์ชันแบบไม่มีชื่อ (Anonymous Function) ใช้ Token => (อ่านว่า goes to) แยกพารามิเตอร์และ Body Syntax { statements; } ตัวอย่าง: หา Index ของเลขคู่แรก x % 2 == 0); Console.WriteLine(Index: + index); // 2 (คือ 40) } } ผลลัพธ์ Index: 2 รูปแบบ Lambda

  9. Hashtable vs Dictionary ใน C# (เปรียบเทียบ)

    Hashtable เข้าถึง Element ด้วย Key มี Key/Value Pair Thread-safe (Members) Return Null ถ้า Key ไม่มี Non-generic Type ช้ากว่า Dictionary (ต้อง Boxing/Unboxing) ประกาศ: Hashtable ht = new Hashtable(); Dictionary Generic Type: Dictionary<TKey, TValue> ใน System.Collections.Generic Throw Error

  10. วิธี Increment Character ใน C# (เพิ่มค่า Char)

    กำหนด Character แล้ว Increment ได้เลย: char ch = K; ch++; พิมพ์จะได้ตัวอักษรถัดไป (L) ตัวอย่าง using System; using System.Collections.Generic; class Demo { static void Main() { char ch = K; Console.WriteLine(Initial character: + ch); // K ch++; // Increment

  11. วิธีพิมพ์ Escape Characters ใน C#

    ตาราง Escape Characters ใน C# และวิธีแสดงผล Escape CharคำอธิบายPatternDisplay \aBell (\u0007)\a\u0007 ใน Warning! + \u0007 \bBackspace (\u0008)[\b]{3,}\b\b\b\b ใน \b\b\b\b \tTab (\u0009)(\w+)\tName\t, Addr\t ใน Name\tAddr\t \rCarriage Return (\u000D)\r\n(\w+)\r\nHello ใน \r\Hello\nWorld. \vVerti

  12. วิธีอ่าน Input จาก Console ใน C#

    ใช้เมธอด ReadLine() อ่าน Input จาก Console รับค่าเป็น String ต้อง Convert ให้เป็น Type ที่ต้องการ ตัวอย่าง: อ่าน Integer string val; Console.Write(Enter integer: ); val = Console.ReadLine(); int a = Convert.ToInt32(val); Console.WriteLine(Your input: {0}, a); ตัวอย่างสมบูรณ์ using System; using Syst

  13. Type Conversion ใน C# (การแปลงชนิดข้อมูล)

    Type Conversion ใน C# แบ่ง 2 แบบ: 1. Implicit Type Conversion Base) 2. Explicit Type Conversion ผู้ใช้ทำเองด้วย Cast Operator ต้องการ Cast Operator Int using System; namespace Demo { class Program { static void Main(string[] args) { double d = 8745.97;

  14. Integer Literals ใน C# (ค่าคงที่จำนวนเต็ม)

    Integer Literal เป็นค่าคงฐานสิบ (Decimal) หรือฐานสิบหก (Hexadecimal) Prefix 0x หรือ 0X = Hexadecimal ไม่มี Prefix = Decimal Suffix U = Unsigned, L = Long ตัวอย่าง 200 // int 90u // unsigned int 30L // long การใช้งาน int a = 200; ตัวอย่างโค้ด using System; namespace Demo { class Progra

  15. File Operations ใน C# (การจัดการไฟล์)

    C# มี File Operations หลัก: Create, Open, Read, Write File Append Delete คลาส FileStream ใน System.IO ช่วย Read/Write/Close ไฟล์ สืบทอดจาก Abstract Class Stream Syntax FileStream FileStream fs = new FileStream( <file_name>, <FileMode>, <FileAccess>, <FileShare&

  16. Mixed Arrays ใน C# (อาร์เรย์ผสม)

    Mixed Arrays = การผสม Multi-dimensional Arrays และ Jagged Arrays หมายเหตุ: Mixed Arrays ล้าสมัย (Obsolete) ตั้งแต่ .NET 4.0 ลบออกแล้ว การประกาศ (ไม่แนะนำ) var x = new object[] {89, 45, jacob, 9.8}; หรือผสม List: var x = new object[] {87, 33, tim, 6.7, new List<string>() {football,tennis,squash

  17. Objects ใน C# (ออบเจกต์และคลาส)

    C# เป็นภาษา Object-Oriented มี Object และ Class Object คือ Entity จริง (Real-world) และเป็น Instance ของ Class เข้าถึง Member ผ่าน Dot Operator (.) Box b1 = new Box(); // สร้าง Object b1.height = 7.0; // Set Property b1.getVolume(); // Call Method ตัวอย่างสมบูรณ์ using System; namespace BoxA

  18. Object Data Types ใน C#

    Object Type กำหนดค่าได้ทุกประเภท (Value, Reference, Predefined, User-defined) แต่ต้อง Type Conversion ก่อน Object Type = Base Class สุดท้ายใน CTS object = Alias ของ System.Object Object = Boxing Value Type = Unboxing ตัวอย่าง object obj; obj = 100; // Boxing ตัวอย่างสมบูรณ์ using System; using S

  19. Nested Namespaces ใน C# (Namespace ซ้อนกัน)

    Namespace ภายใน Namespace เรียกว่า Nested Namespace ใช้จัดโครงสร้างโค้ดให้เป็นระบบ ตัวอย่าง namespace outer { class Program { static void Main(string[] args) { innerClass cls = new innerClass(); Console.WriteLine(Welcome!); Program.display(

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