1
I am learning about overload methods in C# and would like to create a simple program that reads a user’s age and name, but would like to create two methods with the same name (overload) where depending on whether the user has typed their age or not, will show age (if typed) or a message if nothing has been typed (I want to make the age be entered optionally by the user).
I created this little code, but it’s not working:
class Program
{
static void Main(string[] args)
{
string numero; string letra,resultado;
Console.WriteLine("Digite um numero: ");
numero = Console.ReadLine();
Console.WriteLine("Digite uma letra: (opcional)");
letra = Console.ReadLine();
resultado = MostraNaTela(numero, letra);
Console.WriteLine("O resultado é");
}
public static void MostraNaTela(string num)
{
Console.WriteLine("O numero é {0}",num, "Não foi preenchido letra");
}
public static void MostraNaTela(string num2, string letr2)
{
Console.WriteLine(num2);
Console.WriteLine(letr2);
}
}