-1
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();。错误说我需要左侧的变量。性别不是变量吗?

4

1 回答 1

0

除了 Rob 的评论,您还可以致电

Gender = Console.ReadKey().KeyChar;

保持字符数据类型。这也将立即执行,无需按“Enter”。

于 2016-01-17T05:31:49.500 回答