所以我一直在尋找這種感覺像永遠的東西,不知道我做錯了什麼。下面是我的代碼摘錄,我想串CashierLOgInNName的值是新的出納對象名稱:讓用戶輸入字符串並使用該字符串創建對象
public class Cashiers
{
public int CashierID;
public int Password;
public string FirstName;
public string LastName;
public void SetCashiers(int CashierID, int Password,string FirstName, string LastName)
{
this.CashierID = CashierID;
this.Password = Password;
this.FirstName=FirstName;
this.LastName = LastName;
}
Console.WriteLine("enter New Log in name");
string CashierLOgInNName= Console.ReadLine();
Console.WriteLine("enter First Name");
string CashierFirstName = Console.ReadLine();
Console.WriteLine("enter Last name");
string CashierLastName = Console.ReadLine();
Console.WriteLine("enter Cashier ID");
string f = Console.ReadLine();
int NewCashierID = Int32.Parse(f);
Console.WriteLine("enter Cashier Password");
string g = Console.ReadLine();
int NewCashierPWD = Int32.Parse(g);
CashierLOgInNName = (Cashiers)Activator.CreateInstance(null, CashierLOgInNName).Unwrap();
而不是簡單地通過創造新的'收銀員()'類? – abto 2014-10-27 07:53:39