String Firstname, Lastname;
Char Gender = 'm';
Console.WriteLine("Cis247a, Week 2 Lab");
Console.WriteLine("Name: Kyle Landell");
Console.WriteLine("This program accepts user input as a string, then makes the" + Environment.NewLine + "appropriate data conversion and assigns the value to Employee objects");
Console.WriteLine("*********Start Program*********" + Environment.NewLine + Environment.NewLine);
Console.WriteLine("*********Prompt for Emplotee information*********" + Environment.NewLine);
Console.WriteLine("Enter the First name: ");
Firstname = Console.ReadLine();
Console.WriteLine("Enter the Last name: ");
Lastname = Console.ReadLine();
Console.WriteLine("Enter the Gender (M or F): ");
Gender.ToString() = Console.ReadLine();
Console.ReadLine();
这是我的代码。我在Gender.ToString() = Console.ReadLine();
收到错误。错误说我需要左侧的变量。不是性别变量吗?
答案 0 :(得分:0)
除了Rob的评论,您还可以致电
Gender = Console.ReadKey().KeyChar;
保留字符数据类型。这也将立即执行而无需按“输入”。