M
M
Mozzarella2017-05-17 23:06:19
Programming
Mozzarella, 2017-05-17 23:06:19

How to create a common property for two classes?

Bottom line:
There is a room. The room has windows, doors, cutouts in the wall, etc. (let's call them elements).
Created two classes respectively:

class Room{}
class Element{}

The room and the element have standard parameters: Length, Width, Height.
Accordingly, the room object and the element object must have properties with parameters, let's say Dictionary:
class Room { public  Dictionary<string,double> Params {get;set;} }
class Element { public  Dictionary<string,double> Params {get;set;} }
Room room = new Room();
Element element = new Element();
room.Params["Width"]; 
element.Params["Width"];

The room contains many elements, let's say the List<> property How to create a common property of the standard Parameters (Params) for these two classes? If inheritance is applied, then an object of the Element class will also have a list of elements Elements: , which will be incorrect.
public List<Element> Elements {get;set;};
element.Elements[0]["Width"]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2017-05-17
@RidgeA

If I understand correctly, then you can make an Element class that will contain the width, height, length properties.
From this class, inherit the Room class and add List Elements

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question