我正在尝试创建一个构建器,并希望根据特定类型指导用户所需的输入,我尝试实现的示例如下:
class Program
{
static void Main(string[] args)
{
`string name,surname, Input;
int idNumber;
Console.WriteLine("Please type your name:");
name = Console.ReadLine();
Console.WriteLine("Please type your surname:");
surname = Console.ReadLine();
Console.WriteLine("Please type you id number:");
Input = Console.ReadLine();
idNumber = Convert.ToInt32(Input);
Console.WriteLine(" Name:" + name + surname );
Console.WriteLine(" ID number: " + idNumber);
Console.ReadLine();`
}
}
}
在2个单独的示例中,Info类是不同的实现
AddLog<Person>(new Info{Name = "john", LastName = "doe"})
vs
AddLog<Company>(new Info{Name = "company", ParentOrg = "parent company"})
是否有可能出现这种情况,或者不使用泛型?