我希望能夠使用來(lái)自用戶的輸入來(lái)創(chuàng)建和引用一個(gè)類。我是編碼的新手,所以我不太確定解決此問(wèn)題的最佳方法。如果有更好的方法而無(wú)需上課,我愿意提出建議。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;}
如何使用用戶輸入的名稱創(chuàng)建類的實(shí)例,并訪問(wèn)其方法和變量?
翻翻過(guò)去那場(chǎng)雪
2021-04-10 16:08:47