Advertisement
barnabe0057

TP_Collections

Feb 20th, 2022
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MNS // Note: actual namespace depends on the project name.
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Faire une liste des gens co sur zoom
  10.             List<string> personnesSurZoom = new List<string>();
  11.  
  12.             personnesSurZoom.Add("Sandy");
  13.             personnesSurZoom.Add("Gilles");
  14.             personnesSurZoom.Add("Alain");
  15.  
  16.             foreach (string personne in personnesSurZoom)
  17.             {
  18.                 Console.WriteLine(personne);
  19.             }
  20.  
  21.             //Faire un dictionnaire
  22.             Dictionary<string, string> dicoFrancaisAnglais = new Dictionary<string, string>();
  23.  
  24.             dicoFrancaisAnglais.Add("Bonjour", "Hello");
  25.             dicoFrancaisAnglais.Add("Ordinateur", "Computer");
  26.             dicoFrancaisAnglais.Add("Tableau", "Array");
  27.  
  28.             Console.WriteLine(dicoFrancaisAnglais["Ordinateur"]);
  29.             Console.WriteLine(dicoFrancaisAnglais["Tableau"]);
  30.  
  31.             Console.WriteLine(Traduction(dicoFrancaisAnglais, "Bonjour"));
  32.  
  33.             //Test inverse liste
  34.             List<string> listeInversee = InverseListe(personnesSurZoom);
  35.  
  36.             foreach (string personne in listeInversee)
  37.             {
  38.                 Console.WriteLine(personne);
  39.             }
  40.  
  41.         }
  42.  
  43.         //fonction qui traduit un mot
  44.         public static string Traduction(Dictionary<string, string> dictionnaire, string mot)
  45.         {
  46.             return dictionnaire[mot];
  47.         }
  48.  
  49.         //fonction qui inverse une liste
  50.         public static List<string> InverseListe(List<string> liste)
  51.         {
  52.             List<string> listeARenvoyer = new List<string>();
  53.  
  54.             for (int i = liste.Count - 1; i >= 0; i--)
  55.             {
  56.                 listeARenvoyer.Add(liste[i]);
  57.             }
  58.  
  59.             return listeARenvoyer;
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement