这是一个工厂的例子;http://www.dotnetperls.com/factory返回1个东西。我如何改变它来返回像这样的东西;
string device = "";
string deviceTypeID = "";
int deviceTypeCode = 0;
bool true举个例子,在每个具体的类中,我会让它看起来像这样;
string device = "bracelet";
string deviceTypeID = "male";
int deviceTypeCode = 0;
bool true或者,对于另一个具体的类;
string device = "ring";
string deviceTypeID = "female";
int deviceTypeCode = 8;
bool false我认为我需要在每个具体的类中创建一个对象,但由于我对C#非常陌生,这扩展了我的理解。
谢谢!
发布于 2013-11-23 00:12:57
在class中将它们组合在一起
sealed class MyClass
{
public MyClass(string device, string deviceTypeId, int deviceTypeCode, bool someBool)
{
this.Device = device;
this.DeviceTypeId = deviceTypeId;
this.DeviceTypeCode = deviceTypeCode;
this.SomeBool = someBool
}
string Device { get; private set; }
string DeviceTypeId { get; private set; }
int DeviceTypeCode { get; private set; }
bool SomeBool { get; private set; }
}然后在你的factory中返回它。
return new MyClass("bracelet", "male", 0, false);你的类的实现可能会有所不同,我在这里实现了它,以便你只能从它读取(在创建之后不能改变它)。
https://stackoverflow.com/questions/20149292
复制相似问题