diff --git a/Program.cs b/Program.cs index 04e3ea4..873a3a4 100644 --- a/Program.cs +++ b/Program.cs @@ -142,13 +142,7 @@ class Program { while (scelta != 5); Console.WriteLine("Chiusura effettuta con successo"); } - static bool VerificaDoppione(string p_stringa, string[] p_stringhe, int p_contatore) { - bool check = false; - if (p_contatore != 0) { - for (int i = 0; i < p_contatore && !(p_stringhe[i] == p_stringa); i++) ; - } - return check; - } + static bool VerificaCorrettezza(string p_stringa, bool p_tipologia) { /* tipologia=true -> Controllo validità nome @@ -169,8 +163,10 @@ class Program { static bool Controllo(string p_stringa, bool p_tipologia, int p_contatore) { bool ritorno = true; - if (p_stringa.Length > (p_tipologia ? 40 : 20)) { - Console.WriteLine($"Il {(p_tipologia ? "nome" : "numero di telefono")} non può essere lungo più di {(p_tipologia ? "40" : "20")} caratteri"); + const int LUNGHEZZA_NOME = 40; + const int LUNGHEZZA_TELEFONO = 20; + if (p_stringa.Length > (p_tipologia ? LUNGHEZZA_NOME : LUNGHEZZA_TELEFONO)) { + Console.WriteLine($"Il {(p_tipologia ? "nome" : "numero di telefono")} non può essere lungo più di {(p_tipologia ? LUNGHEZZA_NOME : LUNGHEZZA_TELEFONO)} caratteri"); ritorno = false; } if (VerificaCorrettezza(p_stringa, p_tipologia)) { @@ -178,13 +174,10 @@ class Program { ritorno = false; } if (p_contatore != 0) { - if (check3 == true) { - Console.WriteLine("Questo nome esiste già nelle rubrica"); + if (p_stringhe.Contains(p_stringa)) { + Console.WriteLine($"Questo {(p_tipologia ? "nome" : "numero di telefono")} esiste già nelle rubrica."); } } - - return ritorno; - } }