0

所以,假设我有以下内容:

 public class CProperty : CTitledEntity
    {
        private int numberOfNodes;
        private int elementType;

        public CProperty(int id, string title, int numberOfNodes, int elementType, string descripton = "")
            : base(id, title, descripton)
        {
            this.numberOfNodes = numberOfNodes;
            this.elementType = elementType;
        }

        public string Property
        {
            get
            {
                CElement.ElementTypes enumDisplayStatus = ((CElement.ElementTypes)numberOfNodes);
                string stringValue = enumDisplayStatus.ToString();
                return stringValue + elementType;
            }
        }
    }

 public CElement(int id, int numberOfNodes, int index, int[] nodes)
            : base(id)
        {
            this.NumberOfNodes = numberOfNodes;
            this.Nodes = new int[numberOfNodes];
            this.Index = index;
            for (int i = 0; i < numberOfNodes; i++)
                this.Nodes[i] = nodes[i];
        }
        public int NumberOfNodes { get; set; }
        public int[] Nodes { get; set; }
        public int Index { get; set; }
        public CProperty Property { get; set; }

我有一个清单:

CEntityCollection<CProperty> properties = ReadProperty();
CEntityCollection<CElement> elements = ReadElement();

首先,我很抱歉我的英语不好。我必须使用我从属性中提供的 CPropety 参数在 CElement 类中创建构造函数。我不知道该怎么做。

4

1 回答 1

0

只需在您的 CElemenet 类中添加 CProperty 对象并将其添加到构造函数的参数中。

public CElement(int id, int numberOfNodes, int index, int[] nodes, CProperty property) : base(id)
    : base(id)
{
    this.NumberOfNodes = numberOfNodes;
    this.Nodes = new int[numberOfNodes];
    this.Index = index;
    for (int i = 0; i < numberOfNodes; i++)
        this.Nodes[i] = nodes[i];
    Property = property;
}

public CProperty Property { get; set; }
public int NumberOfNodes { get; set; }
public int[] Nodes { get; set; }
public int Index { get; set; }
public CProperty Property { get; set; }
于 2013-02-13T08:02:07.027 回答