c# - C#同时TryParse

标签 c# tryparse

char typeClient = ' ';
bool clientValide = false;
while (!clientValide)
{
     Console.WriteLine("\nEntrez le type d'employé (c ou g) : ");
     clientValide = char.TryParse(Console.ReadLine(), out typeClient);
     if (clientValide)
         typeClient = 'c';
}


我想这样做,除非char是'g'或'c',否则它不会退出一段时间
救命 ! :)

最佳答案

string input;
do {
    Console.WriteLine("Entrez le type d'employé (c ou g):");
    input = Console.ReadLine();
} while (input != "c" && input != "g");

char typeClient = input[0];

关于c# - C#同时TryParse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15465664/

相关文章:

c# - DateTime.TryParse世纪控件C#

c# - 现在开始为任务并行库设计是否为时过早?

c# - .net 中继器与子中继器

c#属性问题

c# - Int64 创建数字范围

Android: Ints.tryParse 始终返回 "null",即使字符串中有数字

c# - 带小数点的 Short.Parse 失败

c# - 有哪些技术可用于发送短信?

c# - TryCatch 与 TryParse 的优缺点

c# - 判断 double/float/int/short/byte 的字符串是否超出范围