Opzione 3
This commit is contained in:
parent
3338996751
commit
cbce1956e1
19
Program.cs
19
Program.cs
@ -41,7 +41,12 @@ class Program {
|
||||
break;
|
||||
case 3:
|
||||
Console.Clear();
|
||||
|
||||
if (array != null) {
|
||||
Console.WriteLine($"La frase più lunga è {MaxLength(array)}");
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Errore: è necessario creare l'array prima di mostrare la frase più lunga.");
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
case 4:
|
||||
@ -94,4 +99,16 @@ class Program {
|
||||
}
|
||||
}
|
||||
|
||||
static string MaxLength(string[] p_array) {
|
||||
int max = 0, maxIndex = 0;
|
||||
for (int i = 0; i < p_array.Length; i++) {
|
||||
if (p_array[i].Length > max) {
|
||||
max = p_array[i].Length;
|
||||
maxIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return p_array[maxIndex];
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user