Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

313
Views
Error de función de cambio de c #, ¿tal vez un malentendido del formato?

hola intenté usar este código para crear un mini conversor de moneda para mi tarea pero no entiendo por qué no funciona, por favor háganme saber por qué puede ser así, gracias.

el error dice que newValue ya ha sido definido.

 switch (userCurrency) { case "USD": double newValue = userEuro * usd; break; case "GBP": double newValue = userEuro * gbp; break; case "CHF": double newValue = userEuro * chf; break; case "AUD": double newValue = userEuro * aud; break; case "CAD": double newValue = userEuro * cad; break; default: Console.WriteLine("Invalid input!"); break; }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

En lugar de declarar newValue dentro de cada case : declárelo una vez (sin asignar un valor) sobre el switch , y simplemente asigne un valor dentro de cada case .

O tal vez use una "expresión de cambio" en su lugar.

over 4 years ago · Santiago Trujillo Report

0

defina "newValue" antes de la declaración de cambio:

 double newValue; switch (userCurrency) { case "USD": newValue = userEuro * usd; break; ...
over 4 years ago · Santiago Trujillo Report

0

Extraiga la declaración newValue fuera del alcance del bloque de casos de cambio y luego asígnela dentro de los diferentes casos de cambio

 double newValue; switch (userCurrency) { case "USD": newValue = userEuro * usd; break; case "GBP": newValue = userEuro * gbp; break; case "CHF": newValue = userEuro * chf; break; case "AUD": newValue = userEuro * aud; break; case "CAD": newValue = userEuro * cad; break; default: Console.WriteLine("Invalid input!"); break; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!