我有这个结构,它是一个类的一部分。
public struct PartStruct
{
public string name;
public string filename;
public string layer2D;
public string layer3D;
public TypeOfPart type;
public int hight;
public int depth;
public int length;
public int flooroffset;
public int width;
public int cellingoffset;
}
这个结构的每个实例将代表一个具有不同属性的部分,我只使用一种结构类型,因为我有这个功能:
public void insert(Partstruct part){//large code to insert the part}
例子:
Partstruct monitor = new Partstruct();
monitor.name = "mon1";
monitor.file = "default monitor file name.jpg";//this is a const for each new monitor
monitor.TypeofPart = monitor;
monitor.layer2d = "default monitor layer";//this will be the same for each new monitor.
ETC..
Partstruct keyboard= new Partstruct();
keyboard.name = "keyboard1";
keyboard.file = "default keyboard file name.jpg";//this is a const for each new keyboard
keyboard.TypeofPart = keyboard;
keyboard.layer2d = "default keyboard 2d layer";//this will be the same for each new keyboard.
keyboard.layer3d = "default keyboard 3d layer"//this will be the same for each new keyboard.
ETC..
insert(monitor);
insert(keyboard);
我能以更聪明的方式做到这一点吗?我正在使用.net 3.5