I have a problem when trying to use variables inside a switch. They are variables that are assigned "outside" (the switch) and when I pass them as parameters it throws the folling error "Use of an unassigned variable""
DateTime startDate, endDate;
switch (int.Parse(cmbRepor.SelectedValue.ToString()))
{
case 1:
startDate = new DateTime(anio, 1, 1);
endDate = new DateTime(anio, 3, 31);
break;
case 2:
startDate = new DateTime(anio, 4, 1);
endDate = new DateTime(anio, 6, 30);
break;
case 3:
startDate = new DateTime(anio, 7, 1);
endDate = new DateTime(anio, 9, 30);
break;
case 4:
startDate = new DateTime(anio, 10, 1);
endDate = new DateTime(anio, 12, 31);
break;
default:
break;
}
ReporteLogica logica = new ReporteLogica();
switch (int.Parse(cmbRepor.SelectedValue.ToString()))
{
case 1:
dgvListado.DataSource = logica.GetReporteClientesCuentasInhabilitadas(startDate, endDate);
break;
case 2:
dgvListado.DataSource = logica.GetReporteClientesCuentasInhabilitadas(startDate, endDate);
break;
case 3:
dgvListado.DataSource = logica.GetReporteClientesCuentasInhabilitadas(startDate, endDate);
break;
case 4:
dgvListado.DataSource = logica.GetReporteClientesCuentasInhabilitadas(startDate, endDate);
break;
default:
break;
}