SlideServe
Menu
Préférences
© SlideServe · v2026

C# Programming

reynold avatar
15 diapositives · 322 Views · Oct 13, 2013

C# Programming. Exceed Camp: Day 3. เนื้อหา. รูปแบบคำสั่งพื้นฐาน โครงสร้างของโปรแกรม C# Classes and Objects Conditional statements Loops Arrays. C# Syntax. ตัวอักษรตัวเล็กและตัวใหญ่มีความแตกต่างกัน p icture b ox ≠ P icture B ox จบคำสั่งด้วยเซมิโคลอน ( ; )

C# Programming - slide 1
01 / 15C# Programming
1 / 17

Télécharger la présentation

C# Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. C# Programming Exceed Camp: Day 3

  2. เนื้อหา • รูปแบบคำสั่งพื้นฐาน • โครงสร้างของโปรแกรม C# • Classes and Objects • Conditional statements • Loops • Arrays

  3. C# Syntax • ตัวอักษรตัวเล็กและตัวใหญ่มีความแตกต่างกัน • picturebox ≠ PictureBox • จบคำสั่งด้วยเซมิโคลอน (;) • กำหนดบล็อกของโปรแกรมด้วยวงเล็บปีกกา ({ }) • ข้อความที่อยู่ระหว่าง /* */และที่ตามหลัง //ถือเป็นคอมเมนต์

  4. จุดเริ่มต้นโปรแกรม โครงสร้างโปรแกรม C# • using System; • namespace MyApplication • { • : • publicclass Form1:System.Windows.Forms.Form • { • private System.Windows.Forms.Button button1; • private System.Windows.Forms.Label label1; • : • staticvoid Main() • { • Application.Run(new Form1()); • } • privatevoid button2_Click(object sender, System.EventArgs e) • { • /* Say Hello */ • label1.Text = “Hello World”; • } • } • }

  5. การใช้ตัวแปร • รูปแบบการประกาศ: <type> <name>; • รูปแบบการให้ค่า: <name> = <expression>; • ตัวอย่าง: int radius; double area; radius = 3+4*5;

  6. ชนิดตัวแปรพื้นฐาน

  7. Class, Object และคำสั่งnew • Member variable คือตัวแปรที่กำหนดคุณสมบัติของวัตถุในคลาส เช่น สี, พันธุ์ • ใช้คำสั่ง new เพื่อสร้าง Object จากคลาส Button btnOk = new Button(); • โปรแกรม C# ต้องประกอบด้วยคลาสอย่างน้อยหนึ่งคลาส Object ด่าง สี = ดำ, พันธุ์ = พุดเดิ้ล Class สุนัข คุณสมบัติ: สี, พันธุ์ Object โฮ่ง สี = น้ำตาล, พันธุ์= เกรย์ฮาวด์

  8. Member Variable/Function • Member variable เป็นตัวแปรที่ประกาศไว้ในคลาส • เรียกใช้ได้ภายใน Object เดียวกัน • Member variable แบบ public ถูกเรียกใช้จาก Object ใดก็ได้ • Member function (method) คือฟังก์ชันที่ประกาศในคลาส • ภายใน Object เดียวกัน method สามารถอ้างถึง member variable และเรียกใช้งาน method อื่นได้ทุกตัว • Method แบบ public สามารถถูกเรียกใช้จาก Object อื่นได้

  9. การเรียกใช้ Member Function/Variable • ภายใน Object เดียวกัน • ระหว่าง Object ต้องอ้างถึงชื่อ Object นั้น ตามด้วยจุด (.) name = “George Lucas”; method2(); anotherObj.name = “George Lucas”; anotherObj.method2();

  10. Member variables ตัวอย่าง publicclass Dog { Color color; string breed; void bark(int volume) { int age; Console.WriteLine(breed); bool isOk; } void fight(Dog anotherDog) { : } } local variables Method

  11. if...else Statement • รูปแบบคำสั่ง: • ตัวอย่าง if (<boolean expression>) { statement1; : } else { statement2; : } if (a == b) { label1.Text = “Right!”; } else { label1.Text = “Wrong!”; }

  12. Loops • while loop • do...while loop • for loop while (<boolean exp>) { : } do { : } while (<boolean exp>); for (<init>; <condition>; <increment>) { : }

  13. Loops in Pascal, C and C#

  14. อาร์เรย์ (Array) • อาร์เรย์หนึ่งมิติ • อาร์เรย์หลายมิติ string[] weekDays; weekDays = new string[] {"Sun","Sat","Mon","Tue","Wed","Thu","Fri"}; int[,] myArray;// 2-dimension myArray = new int[,] {{1,2}, {3,4}, {5,6}, {7,8}};

  15. foreach Statement • ใช้อ้างถึงสมาชิกในอาร์เรย์ตั้งแต่ต้นจนจบ • รูปแบบ: • ตัวอย่าง: foreach (<type> <var> in <array>) { } int[] a = new int[] {1,2,3,4,5}; int sum = 0; foreach (int i in a) { sum = sum + i; }