diff --git a/Program.cs b/Program.cs index a9b0ea4..140c7de 100644 --- a/Program.cs +++ b/Program.cs @@ -8,7 +8,7 @@ class Program { static void Menu() { Console.Clear(); int scelta; - string stringa; + string stringa1, stringa2; do { Console.WriteLine("Inserire un'opzione:"); Console.WriteLine("1. Alterna i caratteri"); @@ -26,7 +26,14 @@ class Program { break; case 1: Console.Clear(); - AlternaCaratteri(); + stringa1 = Input(); + stringa2 = Input(); + if (Controllo(stringa1, stringa2)) { + Console.WriteLine(AlternaCaratteri(stringa1, stringa2)); + } + else { + Console.WriteLine("Errore: le due stringhe devono essere lunghe uguali"); + } Pausa(); break; case 2: @@ -75,32 +82,27 @@ class Program { return Console.ReadLine(); } - static void AlternaCaratteri() { - string stringa1 = Input(); - string stringa2 = Input(); - bool stringa1Max = stringa1.Length > stringa2.Length; - int lunghezza = stringa1Max ? stringa1.Length : stringa2.Length; - - for (int i = 0; i < lunghezza; i++) { - if (stringa1Max) { - if (i < stringa2.Length) { - Console.Write($"{stringa1[i]}{stringa2[i]}"); - } - else { - Console.Write(stringa1[i]); - } - } - else { - if (i < stringa1.Length) { - Console.Write($"{stringa1[i]}{stringa2[i]}"); - } - else { - Console.Write(stringa2[i]); - } - } - + static bool Controllo(string p_stringa1, string p_stringa2) { + bool ritorno; + if (p_stringa1.Length == p_stringa2.Length) { + ritorno = true; } - Console.WriteLine(); + else { + ritorno = false; + } + + return ritorno; + + } + + static string AlternaCaratteri(string p_stringa1, string p_stringa2) { + string ritorno = ""; + + for (int i = 0; i < p_stringa1.Length; i++) { + ritorno = string.Concat(ritorno, p_stringa1[i], p_stringa2[i]); + } + + return ritorno; } static string Codifica() { diff --git a/bin/Debug/net9.0/strings_3.dll b/bin/Debug/net9.0/strings_3.dll index 2ffa3d7..82f117b 100644 Binary files a/bin/Debug/net9.0/strings_3.dll and b/bin/Debug/net9.0/strings_3.dll differ diff --git a/bin/Debug/net9.0/strings_3.pdb b/bin/Debug/net9.0/strings_3.pdb index 692d0d0..9c83287 100644 Binary files a/bin/Debug/net9.0/strings_3.pdb and b/bin/Debug/net9.0/strings_3.pdb differ diff --git a/obj/Debug/net9.0/ref/strings_3.dll b/obj/Debug/net9.0/ref/strings_3.dll index 1cb1859..e6af496 100644 Binary files a/obj/Debug/net9.0/ref/strings_3.dll and b/obj/Debug/net9.0/ref/strings_3.dll differ diff --git a/obj/Debug/net9.0/refint/strings_3.dll b/obj/Debug/net9.0/refint/strings_3.dll index 1cb1859..e6af496 100644 Binary files a/obj/Debug/net9.0/refint/strings_3.dll and b/obj/Debug/net9.0/refint/strings_3.dll differ diff --git a/obj/Debug/net9.0/strings_3.AssemblyInfo.cs b/obj/Debug/net9.0/strings_3.AssemblyInfo.cs index 31f574e..8fd9189 100644 --- a/obj/Debug/net9.0/strings_3.AssemblyInfo.cs +++ b/obj/Debug/net9.0/strings_3.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("strings_3")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d29d204ee494646ce5094700197a900b05cc44aa")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8d0599b65c9adc395c7a863ae0c292a2ea4126c5")] [assembly: System.Reflection.AssemblyProductAttribute("strings_3")] [assembly: System.Reflection.AssemblyTitleAttribute("strings_3")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generato dalla classe WriteCodeFragment di MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache b/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache index 96b12b6..b1f6654 100644 --- a/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache @@ -1 +1 @@ -cbb955859c30d97643b375ba8ca1883b485f554c16cef8a828a4aa0bf8968236 +2a1edca03dfab0d51deb008cf18acd10fc7a6338349d06d54d7fc8dfb3ff671e diff --git a/obj/Debug/net9.0/strings_3.dll b/obj/Debug/net9.0/strings_3.dll index 2ffa3d7..82f117b 100644 Binary files a/obj/Debug/net9.0/strings_3.dll and b/obj/Debug/net9.0/strings_3.dll differ diff --git a/obj/Debug/net9.0/strings_3.pdb b/obj/Debug/net9.0/strings_3.pdb index 692d0d0..9c83287 100644 Binary files a/obj/Debug/net9.0/strings_3.pdb and b/obj/Debug/net9.0/strings_3.pdb differ