如何设置参数化构造函数值

时间:2017-08-04 00:15:28

标签: c#

我想将参数化构造函数值(aName和aValue)设置为attribName和attribValue set方法,请协助。

public class PlayerRow
{
    public PlayerRow(string aName, string aValue)
    {
      AttribsPlayerLine = new List<AttribLine>();
    }
    public List<AttribLine> AttribsPlayerLine { get; set; }

    public class AttribLine
    {

    [Description("AttribName")]
    public string attribName { get; set; }

    [Description("AttribValue")]
    public string attribValue { get; set; }
    }
}

1 个答案:

答案 0 :(得分:0)

如果你能澄清我们可以提供更好的帮助,那么你想要在这里实现的目标有点令人困惑。但如果我理解正确的话,这是我的答案,如果没有请注释,我会编辑我的答案。

public class PlayerRow
{
    public PlayerRow(string aName, string aValue)
    {
        AttribsPlayerLine = new List<AttribLine>();

        AttribLine temp = new AttribLine();
        temp.attribName = aName;
        temp.attribValue = aValue;
        AttribsPlayerLine.Add(temp);
    }
    public List<AttribLine> AttribsPlayerLine { get; set; }

    public class AttribLine
    {

    [Description("AttribName")]
    public string attribName { get; set; }

    [Description("AttribValue")]
    public string attribValue { get; set; }
    }
}

但我真的没有看到任何好处,因为构造函数只会在列表中添加1个项目。但是,您仍然可以访问main中的PlayerRow对象,然后访问AttribsPlayerLine,然后向其添加新的AttribLine。但对我们来说,目前尚不清楚。