我有這個結構是一個類的一部分。如何使這個結構更智能
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_。 –