Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace DPRN2U3A2
- {
- public class DPRN2U3A2
- {
- static void Main(string[] args)
- {
- try
- {
- Console.WriteLine("Por favor ingrese su fecha de nacimiento");
- int yof = Convert.ToInt32(Console.ReadLine());
- if (Enumerable.Range(1980, 1995).Contains(yof))
- {
- throw new YoBFilter("No se puede aplicar la vacuna "); //filtro de excepcion personalizado
- }
- Console.WriteLine("Puede recibir la vacuna");
- var lista = new List<string>();
- List<string> variantesCovid = new List<string>();
- variantesCovid.InsertRange(0, new string[] { "alfa", "beta", "gama", "delta", "omicron", "psi" });
- int[] enteros4 = { 1, 6, 98, 12, 15, 18, 21 };
- int[] enteros5 = new int[6];
- int[] valores = null;
- int[] dividendos = { 20, 7, 0 };
- Console.WriteLine("Número de elementos en la lista:{0}", lista.Count);
- try { Console.WriteLine("El primer elemento de la lista es: {0}", lista[0]); }
- catch (ArgumentOutOfRangeException ex) //handling argument out of range exception
- {
- Console.WriteLine(ex.Message);
- }
- for (int control = 0; control <= variantesCovid.Count; control++)
- try { Console.WriteLine("'{0}' ", variantesCovid[control]); }
- catch (ArgumentOutOfRangeException ex)//handling argument out of range exception
- {
- Console.WriteLine(ex.Message);
- }
- try
- {
- enteros5[enteros4.Length - 1] = enteros4[enteros4.Length - 1];
- }
- catch (IndexOutOfRangeException ex)//handling index out of range exception
- {
- Console.WriteLine(ex.Message);
- }
- try
- {
- for (int i = 0; i <= 9; i++)
- valores[i] = i * 2;
- }
- catch (NullReferenceException ex)
- {
- Console.WriteLine(ex.Message);
- }
- try
- {
- foreach (var values in valores)
- Console.WriteLine(values);
- }
- catch (NullReferenceException ex)
- {
- Console.WriteLine(ex.Message);
- }
- foreach (var value in dividendos)
- {
- try
- {
- Console.WriteLine("{0} dividido entr 2 es {1}", value, DivideEntreDos(value));
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- Console.WriteLine(Divide(1, 0));
- }
- catch (YoBFilter ex) { //excepcion perzonalizada
- Console.WriteLine(ex.Message);
- }
- Console.WriteLine("Presione una tecla para continuar....");
- Console.ReadKey();
- }
- static int DivideEntreDos(int num) {
- if (!((num % 2) == 0))
- {
- throw new ArgumentException(String.Format("{0} no es mumero par", num));//excepcion si el numero no es divisibl entre 2
- }
- return num / 2;
- }
- static double Divide(double dividendo , double divisor) {
- double resultado = 0;
- try {resultado = dividendo / divisor; }
- catch (DivideByZeroException ex) {
- Console.WriteLine(ex.Message);
- }
- return resultado;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment