using System.Collections.Generic;
List<Orque> orques = new List<Orque>();
foreach(string s in new [] { "urg", "bob", "GRR" })
orques.Add(new Orque(s));
Console.WriteLine($"Orque créé : {orques[orques.Count - 1].Nom}");
catch (NomInvalideException ex)
Console.WriteLine(ex.Message);
if (Trier(ref orques, out int nbPermutations))
Console.WriteLine("Les orques ont été entrés en ordre alphabétique");
Console.WriteLine($"Trier les orques a nécessité {nbPermutations} permutations");
Console.Write("La tribu d'orques est :");
foreach (Orque orque in orques)
Console.Write($" {orque.Nom}");
static void Permuter(ref Orque a, ref Orque b)
static bool Trier(ref List<Orque> lst, out int nbPerm)
Orque[] tab = lst.ToArray();
for (int i = 0; i < tab.Length - 1; ++i)
for (int j = i + 1; j < tab.Length; ++j)
if(string.Compare(tab[i].Nom, tab[j].Nom) > 0)
Permuter(ref tab[i], ref tab[j]);
public static bool EstEntreInclusif(int val, int min, int max) =>
min <= val && val <= max;
private static char[] voyelles = { 'a', 'e', 'i', 'o', 'u', 'y' };
public static bool EstVoyelle(char c) => voyelles.Contains(char.ToLower(c));
public static int CompterVoyelles(string s)
class NomInvalideException : Exception
public NomInvalideException(string nom) : base($"Nom invalide : {nom}")
private static bool EstNomValide(string s)
const int MAX_VOYELLES = 1;
return s != null && Algos.EstEntreInclusif(s.Length, LG_MIN, LG_MAX) &&
OutilsTexte.CompterVoyelles(s) <= MAX_VOYELLES;
nom = !EstNomValide(value) ? throw new NomInvalideException(value) : value;