Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#
C#
  1. วิธีทำให้โค้ดใช้ซ้ำได้ใน C#

    ใช้ Interfaces เพื่อทำให้โค้ด Reusable Interface กำหนด Properties, Methods, Events แค่ Declaration Derived Class จะ Implement รายละเอียด ช่วยให้โครงสร้างมาตรฐาน ตัวอย่าง Interface: public interface IShape { void display(); } Convention: ชื่อ Interface เริ่มต้นด้วย I ไม่ต้องระบุ Access Modifier เ

  2. วิธีค้นหา Substring ด้วย Regular Expression ใน C#

    สตริงต้นฉบับ: string str = My make ; Regular Expression หา make: @\bmake\b ตัวอย่าง using System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { private static void showMatch(string text, string expr) { Console.WriteLine(The Express

  3. Formatted Output ใน C#

    จัดรูปแบบ Output สำหรับ Double และ DateTime Double Type using System; class Demo { public static void Main(String[] args) { Console.WriteLine(Three decimal places...); Console.WriteLine(String.Format({0:0.000}, 987.383)); Console.WriteLine(String.Format({0:0.000}, 987.38)

  4. Formatted String Literals ใน C#

    ใช้ String.Format จัดรูปแบบสตริง {0} คือ Index ของ Object ตัวอย่างที่ 1 using System; namespace Demo { class Test { static void Main(string[] args) { decimal A = 15.2m; string res = String.Format(Temperature = {0}°C., A); Console.WriteLine(res);

  5. วิธีแปลง List เป็น String ใน C#

    ประกาศ List และเพิ่มข้อมูล: List<string> l = new List<string>(); l.Add(Accessories); l.Add(Footwear); l.Add(Watches); แปลงเป็น String ด้วย string.Join: string str = string.Join( , l.ToArray()); ตัวอย่าง using System; using System.Collections.Generic; class Demo { static void Main() {

  6. โปรแกรม C# ตรวจสอบว่ามีคู่เลขใดบวกกันได้ผลลัพธ์ที่กำหนดหรือไม่

    กำหนดอาร์เรย์และค่าเป้าหมาย: int[] arr = new int[] { 7, 4, 6, 2 }; int res = 8; วนลูป 2 ชั้น หาคู่ที่บวกกันได้ res: for (int i = 0; i < arr.Length; i++) { for (int j = 0; j < arr.Length; j++) { if (i != j) { int sum = arr[i] + arr[j]; if (sum == res) {

  7. โปรแกรม C# แสดงค่าที่ไม่ซ้ำกันในอาร์เรย์จำนวนเต็ม

    ใช้ Dictionary เก็บค่าและนับจำนวน: int[] arr = { 88, 23, 56, 96, 43 }; var d = new Dictionary<int, int>(); วนลูปนับ แล้วแสดงค่าที่มี Count = 1 ตัวอย่าง using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) {

  8. โปรแกรม C# แปลงสกุลเงิน

    ตัวอย่างแปลง 10 ดอลลาร์เป็นบาท: double usd, inr, val; usd = 10; val = 69; inr = usd * val; ตัวอย่าง using System; namespace Demo { public class Program { public static void Main(string[] args) { Double usd, inr, val; usd = 10; val = 69; inr

  9. โปรแกรม C# แยกเลขคู่และคี่เป็นอาร์เรย์ต่างกัน

    สร้างอาร์เรย์ 2 อันสำหรับเลขคู่และคี่: int[] arr2 = new int[5]; int[] arr3 = new int[5]; วนลูปตรวจสอบ mod 2 แล้วแยกเก็บ: if (arr1[i] % 2 == 0) { arr2[j] = arr1[i]; j++; } else { arr3[k] = arr1[i]; k++; } ตัวอย่าง using System; namespace Demo { public class Program { publi

  10. โปรแกรม C# หาค่ามากที่สุด น้อยที่สุด อันดับ 2 มาก และน้อยใน List

    กำหนดข้อมูล: var val = new int[] { 99, 35, 26, 87 }; ใช้ LINQ: z).Skip(1).First(); // อันดับ 2 น้อย ตัวอย่าง z).Skip(1).First(); Console.WriteLine(Second Smallest Number: + secondMin); } } ผลลัพธ์ Maximum Number: 99 Minimum Number: 26 Second Largest Number: 87 Second Smalles

  11. Object Pool ใน C# คืออะไร

    Object Pool เป็น Software Construct เพื่อเพิ่มประสิทธิภาพการใช้ Resource จำกัด มี Object พร้อมใช้งาน รูปแบบ 2 แบบ: Activate - ดึง Object จาก Pool Deactivate - คืน Object กลับ Pool ตั้งค่าด้วย ObjectPoolingAttribute บนคลาสที่繼承 System.EnterpriseServices.ServicedComponent ใช้ Diagnostics ตรว

  12. โปรแกรม C# นับจำนวนครั้งที่ตัวอักษรปรากฏในสตริง

    กำหนดสตริง: String s = mynameistomhanks; สร้างอาร์เรย์นับและเมธอดคำนวณ: static void calculate(String s, int[] cal) { for (int i = 0; i < s.Length; i++) cal[s[i]]++; } ตัวอย่าง using System; class Demo { static int maxCHARS = 256; static void calculate(String s, int[] cal) {

  13. StringTemplate Class ใน C#

    StringTemplate ใช้ Parse Format String ให้เข้ากับ String.Format มาจาก NString Library มี Extension Methods: IsNullOrEmpty() IsNullOrWhiteSpace() Join() Truncate() Left() Right() Capitalize() StringTemplate.Format อ่านง่ายกว่า String.Format ใช้ Named Placeholders แทน Numbered Placeholders ตัวอย่าง: s

  14. Abstraction ใน C# คืออะไร

    Abstraction และ Encapsulation เกี่ยวข้องกัน Abstraction แสดงข้อมูลที่เกี่ยวข้อง Encapsulation ช่วย Implement ระดับ Abstraction ที่ต้องการ ใน C# ทำได้ด้วย Abstract Class ให้ Implementation บางส่วน Derived Class จะ Implement ให้สมบูรณ์ จุดสำคัญ: ไม่สามารถสร้าง Instance ของ Abstract Class ได้

  15. ตัวเลือกแทน CopyOnWriteArrayList ใน C#

    Java มี CopyOnWriteArrayList แต่ C# ไม่มี ให้ใช้ SynchronizedCollection<T> แทน Syntax: public class SynchronizedCollection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection Properties: ลำดับProperty & Description

  16. การซิงโครไนซ์และ Pooling ของ Process ใน C#

    ใช้ Synchronization ควบคุมการเข้าถึง Resource ในแอป Multi-threaded Mutex ใช้ซิงโครไนซ์เธรดข้าม Process ป้องกันการรันโค้ดบล็อกเดียวกันพร้อมกัน lock statement ใช้ให้บล็อกโค้ดรันโดยไม่ถูก Interrupt โดยเธรดอื่น Thread Pool คือกลุ่มเธรดสำหรับงาน Background เมื่อเธรดทำงานเสร็จ จะถูกคืนกลับ Queue เพื่อนำกล

Total 2668 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:36/134  20-คอมพิวเตอร์/Page Goto:1 30 31 32 33 34 35 36 37 38 39 40 41 42