From 0dc3eed65f04928e028a1afc17f4bc8f367f78bd Mon Sep 17 00:00:00 2001 From: La Programmatrice Verde Date: Thu, 15 May 2025 10:02:44 +0200 Subject: [PATCH] Pronto per verifica delle eccezioni (non so quali vengano sollevate) --- Program.cs | 137 +++++++++++++++++- ...CoreApp,Version=v9.0.AssemblyAttributes.cs | 4 + obj/Debug/net9.0/eccezioni_1.AssemblyInfo.cs | 22 +++ .../eccezioni_1.AssemblyInfoInputs.cache | 1 + ....GeneratedMSBuildEditorConfig.editorconfig | 15 ++ .../net9.0/eccezioni_1.GlobalUsings.g.cs | 8 + obj/Debug/net9.0/eccezioni_1.assets.cache | Bin 0 -> 149 bytes 7 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs create mode 100644 obj/Debug/net9.0/eccezioni_1.AssemblyInfo.cs create mode 100644 obj/Debug/net9.0/eccezioni_1.AssemblyInfoInputs.cache create mode 100644 obj/Debug/net9.0/eccezioni_1.GeneratedMSBuildEditorConfig.editorconfig create mode 100644 obj/Debug/net9.0/eccezioni_1.GlobalUsings.g.cs create mode 100644 obj/Debug/net9.0/eccezioni_1.assets.cache diff --git a/Program.cs b/Program.cs index c33dcaa..e6fd6f1 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,136 @@ namespace eccezioni_1; -class Program -{ - static void Main(string[] args) - { - Console.WriteLine("Hello, World!"); +class Program { + static void Main(string[] args) { + int scelta = 0; + double input = 0; + bool eccezione; + int[] array = null; + do { + + + Console.WriteLine("Scegliere un'opzione:"); + Console.WriteLine("1. NullPointerException array"); + Console.WriteLine("2. NullPointerExceptiopn stringa"); + Console.WriteLine("3. DivideByZeroException"); + Console.WriteLine("4. IndexOutOfBoundException"); + Console.WriteLine("0. Esci"); + Console.Write("Scelta: "); + + eccezione = false; + try { + scelta = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + Console.WriteLine("Opzione non valida."); + Pausa(); + eccezione = true; + } + if (!eccezione) { + switch (scelta) { + case 0: + break; + case 1: + //try { + int[] T = null; + T[0] = 7; + //} + break; + case 2: + //try{ + String s = null; + int l = s.Length; + //} + break; + case 3: + do { + Console.Write("Inserire un numero: "); + eccezione = false; + try { + input = Convert.ToDouble(Console.ReadLine()); + } + catch (FormatException) { + Console.WriteLine("Numero non valido"); + Pausa(); + eccezione = true; + } + } + while (eccezione); + + Console.WriteLine($"Il risultato della divisione è {Divisione(input)}"); + break; + case 4: + array = Vettore(); + for (int i = 0; i < array.Length; i++) { + Console.WriteLine($"Elemento n. {i}: {array[i]}"); + } + Pausa(); + break; + default: + Console.WriteLine("Opzione non valida."); + Pausa(); + break; + } + } + } + while (eccezione || scelta != 0); + } + + static void Pausa() { + Console.WriteLine("Premere un tasto per continuare. . ."); + Console.ReadKey(); + } + + static double Divisione(double input) { + Random r = new Random(); + bool eccezione; + double ritorno = 0; + do { + eccezione = false; + try { + ritorno = input / r.Next(0, 4); + } + catch (DivideByZeroException) { + Console.WriteLine("Impossibile dividere per 0."); + Pausa(); + eccezione = true; + } + } while (eccezione); + return ritorno; + } + + static int[] Vettore() { + int[] ritorno = new int[5]; + int inputIndex = 0; + bool eccezione; + do { + Console.Write("In quale posizione inserire il numero? "); + eccezione = false; + try { + inputIndex = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + Console.WriteLine("Numero non valido."); + Pausa(); + eccezione = true; + } + if (!eccezione) { + do { + Console.Write("Inserire un numero: "); + eccezione = false; + try { + ritorno[inputIndex] = Convert.ToInt32(Console.ReadLine()); + } + catch (FormatException) { + Console.WriteLine("Numero non valido"); + Pausa(); + eccezione = true; + } + } + while (eccezione); + } + } + while (eccezione); + return ritorno; } } diff --git a/obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs b/obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs new file mode 100644 index 0000000..9e76325 --- /dev/null +++ b/obj/Debug/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")] diff --git a/obj/Debug/net9.0/eccezioni_1.AssemblyInfo.cs b/obj/Debug/net9.0/eccezioni_1.AssemblyInfo.cs new file mode 100644 index 0000000..e869ac5 --- /dev/null +++ b/obj/Debug/net9.0/eccezioni_1.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("eccezioni_1")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2c4f0d282678697de35d9d6f8a7a44d19dfc5599")] +[assembly: System.Reflection.AssemblyProductAttribute("eccezioni_1")] +[assembly: System.Reflection.AssemblyTitleAttribute("eccezioni_1")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// Generated by the MSBuild WriteCodeFragment class. + diff --git a/obj/Debug/net9.0/eccezioni_1.AssemblyInfoInputs.cache b/obj/Debug/net9.0/eccezioni_1.AssemblyInfoInputs.cache new file mode 100644 index 0000000..0d46c60 --- /dev/null +++ b/obj/Debug/net9.0/eccezioni_1.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +a135b94a2973b38148c12c68634384a95bd847d487811137403326600055d751 diff --git a/obj/Debug/net9.0/eccezioni_1.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net9.0/eccezioni_1.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..cefc56d --- /dev/null +++ b/obj/Debug/net9.0/eccezioni_1.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,15 @@ +is_global = true +build_property.TargetFramework = net9.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = eccezioni_1 +build_property.ProjectDir = /home/Verde/git/eccezioni_1/ +build_property.EnableComHosting = +build_property.EnableGeneratedComInterfaceComImportInterop = +build_property.EffectiveAnalysisLevelStyle = 9.0 +build_property.EnableCodeStyleSeverity = diff --git a/obj/Debug/net9.0/eccezioni_1.GlobalUsings.g.cs b/obj/Debug/net9.0/eccezioni_1.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/obj/Debug/net9.0/eccezioni_1.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using global::System; +global using global::System.Collections.Generic; +global using global::System.IO; +global using global::System.Linq; +global using global::System.Net.Http; +global using global::System.Threading; +global using global::System.Threading.Tasks; diff --git a/obj/Debug/net9.0/eccezioni_1.assets.cache b/obj/Debug/net9.0/eccezioni_1.assets.cache new file mode 100644 index 0000000000000000000000000000000000000000..14bdcb41c6737582d6c8bad808771dfd990c92f2 GIT binary patch literal 149 zcmWIWc6a1qU|@KXY+jM|>ge)AKZWFN)Ar3eWs)>)H}hlu4+-8@MsiM_6M<@o1&lz2 kGWr?$xvBbLsYNNN`g(b#>8U091&PVoiRr1u`h*Mu092J5D*ylh literal 0 HcmV?d00001