Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int suma = Sumar2(10,20,30,40,50, "1000");
- Console.WriteLine(suma);
- Console.ReadKey();
- }
- static int Sumar(params object[] numeros)
- {
- int suma = 0;
- foreach (var item in numeros)
- {
- if (item is int)
- {
- suma += (int)item;
- }
- else if (item is string)
- {
- //int convertido2 = int.Parse((string)item);
- bool convertido = int.TryParse((string)item, out int temporal);
- if (convertido)
- {
- suma += temporal;
- }
- else
- {
- throw new Exception("Valor no numerico");
- }
- }
- else
- {
- throw new Exception("Valor no numerico");
- }
- }
- return suma;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement