我有这个结构是一个类的一部分。如何使这个结构更智能
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.
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.
等。
insert(monitor);
insert(keyboard);
我可以用更聪明的方式做到这一点吗?我正在使用.net 3.5
基础类型和继承或接口类型如何?很难理解你想要实现的目标 - 你可以在插入 – Charleh
之后对你正在做什么和你期望做的功能/列表发表评论吗? – MethodMan
顺便说一句,你为什么使用结构而不是类呢?在这种情况下,更智能的_struct_将是_class_。 –