C# - Utiliser un char dans une condition

Résolu
Utilisateur anonyme -  
 le père -
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
A voir également:

1 réponse

le père
 
Bonjour

if (choix == 'K')
3