C# - Utiliser un char dans une condition

Résolu/Fermé
Utilisateur anonyme - Modifié par Pingouin7 le 16/10/2011 à 18:47
 le père - 16 oct. 2011 à 21:47
Bonjour,

Je tente d'effectuer un travail et je dois faire une condition selon si l'utilisateur entre K, F ou C.

Voici la partie de code problématique:

  Console.WriteLine("Entrez la température choisie. [K/F/C]");  
  string sChoix = Console.ReadLine();  
  choix = Convert.ToChar(sChoix);  
  if (choix = "K")  


csc me dit "no1.cs(15,15): error CS0029: Cannot implicitly convert type 'string' to 'char'" quand je tente de compiler.

J'ai essayé de changer if (choix = "K") pour mettre if (choix = 'K'), mais ça ne marche pas plus et ça donne "Cannot implixitly convert type 'char' to 'bool'" à la place.

ありがとう



Still Alive

1 réponse

Bonjour

if (choix == 'K')
3