Formation C# - Cours 2 - Programmation procédurale
-
Upload
kemenaran -
Category
Technology
-
view
9.368 -
download
0
description
Transcript of Formation C# - Cours 2 - Programmation procédurale
![Page 1: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/1.jpg)
Formation C#
Pierre de La MorinerieClub Microsoft Isep — 2007
Cours n° 2 : Programmation procédurale
![Page 2: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/2.jpg)
Plan
•Introduction, premiers pas, concepts
•Programmation procédurale
•Programmation objet
•Programmation Windows
![Page 3: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/3.jpg)
Prog. procédurale
•Programmation procédurale :
➡Très fortement hérité du C
➡Syntaxe et opérateurs similaires
![Page 4: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/4.jpg)
Prog. procédurale
•Les types de bases :
➡Numériques : int, long, double...
➡Alphabétiques : char, string
➡Booléen : bool
![Page 5: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/5.jpg)
Prog. procédurale
•Déclaration une variable :
➡<type> <nom> = <valeur>;
•Exemple :
➡ int answer = 42;
➡ string nom = “Ford Escort”
![Page 6: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/6.jpg)
Prog. procédurale
•Opérations :
➡“+, -, *, /” sur les nombres
➡“+” sur les strings : concaténation
![Page 7: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/7.jpg)
Prog. procédurale•TP 2 : Salutations
➡Demander le prénom puis le nom
➡Afficher “Bonjour <prénom> <nom> !”
•Outils :
➡ void Console.WriteLine(string)
➡ string Console.ReadLine()
![Page 8: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/8.jpg)
Prog. procédurale
•Structures conditionnelles
➡ if (<condition>) { // si la condition est vraie} else { // sinon}
![Page 9: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/9.jpg)
Prog. procédurale
•Opérateurs conditionnels :
➡Comparaison : “<, >=, <, <=”
➡Egalité : “==”
➡Logique : “&&, ||”
![Page 10: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/10.jpg)
Prog. procédurale
•Opérateur de sélection : switch
➡ switch (<variable>) { case <valeur>: // code break; case <valeur2>: // autre code break;}
![Page 11: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/11.jpg)
Prog. procédurale
•TP 3 : analyse numérique
➡Demander un nombre
➡Dire si ce nombre est supérieur, inférieur ou égal à zéro
•Outils :
➡ Int32.Parse(string)
![Page 12: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/12.jpg)
Prog. procédurale
•Boucles :
➡ while(<condition>) { // code}
![Page 13: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/13.jpg)
Prog. procédurale
•Boucles :
➡ for(int i = 1; i < 5; i++) { // code}
![Page 14: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/14.jpg)
Prog. procédurale
•Boucles :
➡ for(int i = 1; i < 5; i++) { // code}
![Page 15: Formation C# - Cours 2 - Programmation procédurale](https://reader033.fdocuments.fr/reader033/viewer/2022061213/5497365bb479598e638b4649/html5/thumbnails/15.jpg)
Prog. procédurale
•TP 4 : puissance
➡Demander un nombre x
➡Demander un nombre y
➡Afficher xy
•Outils :
➡Boucle