2
I’m doing a program interface on switch
using C# to find out what a couple’s wedding anniversary is, only that I do not know how to insert the result variable for the case default
if the marriage is not 25, 50 and 75 (type can be 21, 32, 45 years of marriage). What I must do to show the value in this case if it does not meet the previous conditions of 25, 50 and 75 years of married.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TesteSwitch1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
int resultado, ano_atual, ano_casaram;
ano_atual = Convert.ToInt32(txtAA.Text);
ano_casaram = Convert.ToInt32(txtAC.Text);
resultado = ano_atual - ano_casaram;
switch (resultado)
{
case 25:
MessageBox.Show("25 anos de casado! BODAS DE PRATA!", "Mensagem");
break;
case 50:
MessageBox.Show("50 anos de casado! BODAS DE OURO!", "Mensagem");
break;
case 75:
MessageBox.Show("75 anos de casado! BODAS DE DIAMANTE!", "Mensagem");
break;
default:
MessageBox.Show("", "Mensagem"); // Aqui que está a minha dúvida
break;
}
}
private void Button2_Click(object sender, EventArgs e)
{
txtAA.Text = "";
txtAC.Text = "";
}
}
}
I was giving error, I looked well and it was :). But why that invalid year if before the code?
– user141036
I think this can help you https://answall.com/q/16089/101 This too: https://answall.com/q/90981/101
– Maniero
Remember: you need C# 6.0+ to have Interpolated Strings support.
– CypherPotato