First at all, i started to learn C# a few days ago, at the moment i’m in the “Set/Get” Chapter. So every new thing that comes in my tutorial i try to apply it on my small application. Even tho if i do not understand the concepts i go the alternative places and look for suggestions, which is not this case.
I tought that maybe in the Class Calculator i could add a set and get so i do not have to declare the num1, num2 variables on each method? (Sumar, Restar, Division, Multiplicacion)
class Calculo
{
public static void Suma()
{
int num1, num2 = 0; Console.Write(" Ingrese el primer numero que quiere sumar: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write(" Ingrese el segundo numero que quiere sumar: "); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(" Resultado es: " + (num1 + num2));
}
public static void Resta()
{
int num1, num2 = 0; Console.Write(" Ingrese el primer numero que quiere restar: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write(" Ingrese el segundo numero que quiere restar: "); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(" Resultado es: " + (num1 - num2));
}
public static void Division()
{
int num1, num2 = 0; Console.Write(" Ingrese el primer numero que quiere Dividir: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write(" Ingrese el segundo numero que quiere Dividir: "); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(" Resultado es: " + (num1 / num2));
}
public static void Multiplicacion()
{
int num1, num2 = 0; Console.Write(" Ingrese el primer numero que quiere multiplicar: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write(" Ingrese el segundo numero que quiere multiplicar: "); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(" Resultado es: " + (num1 * num2));
}
}
Thank you!
Top comments (1)
Instead of using int you could make it faster by using var this way it will be ms faster but will be more modern. 🥹