我希望能够使用来自用户的输入来创建和引用一个类。我是编码的新手,所以我不太确定解决此问题的最佳方法。如果有更好的方法而无需上课,我愿意提出建议。
class Program
{
static void Main(string[] args)
{
Console.WriteLine("What is the name of the Salesmen?");
string userInput = Console.ReadLine();
//Create Class Instance
Salesmen[userInput] = new Salesmen();
//Access Class Methods or Variables
[userInput].Age = 35;
}
}
class Salesmen
{
public int Age;
public int Salary;
}
相关分类