Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#
C#
  1. วิธีการกำหนดอาร์เรย์มิติเดียว (Single-dimensional Array) ใน C#

    อาร์เรย์ใช้เก็บชุดข้อมูล แต่คิดว่ามันเป็นชุดตัวแปรชนิดเดียวกันที่เก็บในหน่วยความจำติดกันจะเข้าใจง่ายกว่า การกำหนดอาร์เรย์มิติเดียว: int[] runs = new int[10]; กำหนดค่าเริ่มต้นในบรรทัดเดียว: int[] runs = new int[5] {125, 173, 190, 264, 188}; ตัวอย่างเต็ม using System; namespace Program { cl

  2. Type Casting (การแปลงชนิดข้อมูล) ใน C# คืออะไร

    Type casting คือการแปลงชนิดข้อมูลหนึ่งเป็นอีกชนิดหนึ่ง มี 2 รูปแบบ: Implicit type conversion (การแปลงโดยนัย) - C# ทำให้อัตโนมัติอย่างปลอดภัย เช่น แปลงจากชนิดเล็กไปใหญ่ หรือจาก derived class ไป base class Explicit type conversion (การแปลงแสดงเจตนา) - ทำโดยโปรแกรมเมอร์ด้วยฟังก์ชันสำเร็จรูป ต้องใช้ c

  3. วิธีการกำหนดโครงสร้าง (Structure) ใน C#

    ใน C# โครงสร้าง (struct) เป็นชนิดข้อมูลแบบค่า (value type) ช่วยให้ตัวแปรเดียวจัดเก็บข้อมูลที่เกี่ยวข้องหลายชนิดข้อมูลได้ ใช้คีย์เวิร์ด struct ในการสร้าง รูปแบบการประกาศ: struct Books { public string title; public string author; public string subject; public int book_id; }; ตัวอย่า

  4. วิธีการกำหนดคลาสอาร์เรย์ (Array Class) ใน C#

    คลาส Array เป็นคลาสฐานสำหรับอาร์เรย์ทุกตัวใน C# อยู่ในเนมสเปซ System มีคุณสมบัติหลักดังนี้: No.Property & Description 1IsFixedSize - อาร์เรย์มีขนาดคงที่หรือไม่ 2IsReadOnly - อาร์เรย์เป็น read-only หรือไม่ 3Length - จำนวนสมาชิกทั้งหมด (32-bit) 4LongLength - จำนวนสมาชิกทั้งหมด (64-bit) 5Rank

  5. การโคลน (Cloning) อาร์เรย์ใน C#

    การโคลนใน C# มีประโยชน์หากต้องการสร้างสำเนาของอาร์เรย์ เมธอด Clone() ใช้สร้างสำเนาที่คล้ายกัน C# มีทั้งเมธอด Clone และอินเทอร์เฟซ ICloneable ตัวอย่าง using System; class Program { static void Main() { string[] arr = { one, two, three, four, five }; string[] arrCloned = arr.Clo

  6. วิธีการล้างค่าอาร์เรย์ใน C#

    ในการล้างค่าอาร์เรย์ใน C# ให้ใช้เมธอด Array.Clear() เมธอดนี้จะล้างค่า (ทำให้เป็นศูนย์) ของสมาชิกทั้งหมด ตัวอย่าง using System; class Program { static void Main() { int[] arr = new int[] {88, 45, 76}; Console.WriteLine(Array (Old):); foreach (int val in arr) {

  7. อาร์กิวเมนต์บรรทัดคำสั่ง (Command Line Arguments) ใน C#

    หากต้องการส่งผ่านอาร์กิวเมนต์ผ่านบรรทัดคำสั่ง ให้ใช้ command line arguments ใน C# เมื่อสร้างโปรแกรมใน C# จะใช้ static void Main(string[] args) โดย string[] args คือตัวแปรที่เก็บค่าทั้งหมดที่ส่งมาจากบรรทัดคำสั่ง ตัวอย่างการอ่านอาร์กิวเมนต์ Console.WriteLine(Length of the arguments: + args.Length)

  8. การใช้ sizeof() หาขนาดชนิดข้อมูลหรือตัวแปรใน C#

    ออเปอเรเตอร์ sizeof() คืนค่าขนาดของชนิดข้อมูล (เป็นไบต์) ตัวอย่าง: sizeof(int); // 4 sizeof(double); // 8 ตัวอย่างครบถ้วน using System; namespace Demo { class Program { static void Main(string[] args) { Console.WriteLine(The size of int is {0}, sizeof(int));

  9. วิธีหาความยาวของอาร์เรย์ใน C#

    เพื่อหาความยาวของอาร์เรย์ ให้ใช้คุณสมบัติ Array.Length (หรือ arr.Length) ตัวอย่าง using System; class Program { static void Main() { int[] arr = new int[10]; int arrLength = arr.Length; Console.WriteLine(Length of the array: + arrLength); } } ผลลัพธ์ Length of t

  10. วิธีหาจำนวนมิติของอาร์เรย์ใน C#

    เพื่อหาจำนวนมิติของอาร์เรย์ ให้ใช้คุณสมบัติ Rank arr.Rank โดยที่ arr คืออาร์เรย์ของเรา: int[,] arr = new int[3,4]; หากต้องการทราบจำนวนแถวและคอลัมน์ ให้ใช้คุณสมบัติ GetLength: arr.GetLength(0); // แถว arr.GetLength(1); // คอลัมน์ ตัวอย่างเต็ม using System; class Program { static void Main

  11. คุณสมบัติ Capacity ของคลาส ArrayList ใน C#

    คุณสมบัติ Capacity ในคลาส ArrayList ใช้ได้หรือตั้งค่าจำนวนสมาชิกที่ ArrayList จุได้ Capacity จะมีค่ามากกว่า Count เสมอ ค่าเริ่มต้นคือ 4 หากมี 5 สมาชิก Capacity จะเพิ่มเป็น 2 เท่า คือ 8 และเพิ่มไปเรื่อยๆ ตัวอย่าง using System; using System.Collections; class Demo { public static void Main() {

  12. คุณสมบัติ Count ของคลาส ArrayList ใน C#

    คุณสมบัติ Count ในคลาส ArrayList ใช้นับจำนวนสมาชิกใน ArrayList ตัวอย่าง using System; using System.Collections; class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); arrList.Add(

  13. คุณสมบัติ Capacity ของคลาส SortedList ใน C#

    คุณสมบัติ Capacity ในคลาส SortedList แสดงขนาดสูงสุดของ SortedList ค่า Capacity เริ่มต้นของ SortedList คือ 16 ตัวอย่าง using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList s = new SortedList(); s.

  14. คุณสมบัติ Count ของคลาส BitArray ใน C#

    นับจำนวนสมาชิกในคลาส BitArray โดยใช้คุณสมบัติ Count ตัวอย่าง using System; using System.Collections; public class Demo { public static void Main() { BitArray arr = new BitArray(10); Console.WriteLine(Count: {0}, arr.Count); } } ผลลัพธ์ Count: 10

  15. คุณสมบัติ Count ของคลาส Hashtable ใน C#

    เพื่อหาจำนวนสมาชิกของ Hashtable ให้ใช้คุณสมบัติ Count ตัวอย่าง using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add(One, Tom); ht.Add(Two, Jack);

  16. คุณสมบัติ Count ของคลาส Queue ใน C#

    ใช้คุณสมบัติ Count เพื่อหาจำนวนสมาชิกของคลาส Queue ตัวอย่าง using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Queue q = new Queue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3);

  17. คุณสมบัติ Count ของคลาส Stack ใน C#

    เพื่อหาจำนวนสมาชิกที่เพิ่มในคลาส Stack ให้ใช้คุณสมบัติ Count ตัวอย่าง using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { Stack st = new Stack(); st.Push(H); st.Push(I); st.Push(J);

  18. วิธีการสร้างออบเจ็กต์ใหม่ใน C#

    เช่นเดียวกับภาษา object-oriented อื่นๆ C# ก็มีออบเจ็กต์และคลาส ออบเจ็กต์คือสิ่งมีชีวิตจริงและเป็นอินสแตนซ์ของคลาส เข้าถึงสมาชิกของคลาสโดยใช้ออบเจ็กต์ เพื่อเข้าถึงสมาชิกของคลาส ให้ใช้ตัวดำเนินการจุด (.) หลังชื่อออบเจ็กต์ ตัวดำเนินการจุดเชื่อมชื่อออบเจ็กต์กับชื่อสมาชิก: Box Box1 = new Box(); ใช้เข้

  19. ออเปอเรเตอร์ Left Shift และ Right Shift (>> และ <<) ใน C#

    Bitwise Left Shift Operator (<<) ค่าของตัวถูกดำเนินการด้านซ้ายจะถูกเลื่อนไปทางซ้ายตามจำนวนบิตที่ระบุโดยตัวดำเนินการด้านขวา Bitwise Right Shift Operator (>>) ค่าของตัวถูกดำเนินการด้านซ้ายจะถูกเลื่อนไปทางขวาตามจำนวนบิตที่ระบุโดยตัวดำเนินการด้านขวา ตัวอย่าง using System; namespace Dem

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:9/134  20-คอมพิวเตอร์/Page Goto:1 3 4 5 6 7 8 9 10 11 12 13 14 15