C#将列表/列表添加到数据类实例

时间:2017-09-20 10:36:05

标签: c#

C#非常新,我正在尝试创建一个节点数据列表,其中包含链接数据的变量列表长度。

  class Data
{
    public List<Node> Node { get; set; }
}

public class Node
{
    public string viewer { get; set; }
    public int viewerId { get; set; }
    public string log { get; set; }
    public List <Link> Link { get; set; }
}

public class Link
{
    public string keyName { get; set; }
    public int value { get; set; }

}

我有一个for循环遍历配置的节点和内部for循环 抓取任何已配置的链接。

Data data = new Data();
data.Node = new List<Node>();

我正在为每个新节点执行以下操作,这是我想要的方式。

 data.Node.Add( new Node {
                    viewer = setup.Device[moduleNr].viewer,
                    viewerId = setup.Device[moduleNr].viewerId ,
                    log = setup.Device[moduleNr].log
                    // how to add one or more lists of Link to this list???                       
                });

我遇到的问题是在现有数据中添加新列表/列表。节点

最终我想实现以下目标 -

data
|->Node
       |->[0]
           |->Link
                 |->[0]
                     |->keyname
                     |->value
                 |->[1]
                     |->keyname
                     |->value
                 |->[2]
                     |->keyname
                     |->value
           |->log
           |->viewerId
           |->viewer

    |->[1]
           |->Link
                 |->[0]
                     |->keyname
                     |->value
                 |->[1]
                     |->keyname
                     |->value

           |->log
           |->viewerId
           |->viewer
        |->[2]
           |->Link
                 |->[0]
                     |->keyname
                     |->value
           |->log
           |->viewerId
           |->viewer

非常感谢这个问题的一些帮助 - 谢谢

1 个答案:

答案 0 :(得分:2)

您可以像这样添加 $ ps + PID TTY TIME CMD | 10178 pts/2 00:00:00 bash | 10197 pts/2 00:00:00 ps | | $ ./procstat.sh 10178 | utime: 2 stime: 1 cutime:1 cstime: 3 | utime: 2 stime: 1 cutime:1 cstime: 3 | utime: 2 stime: 1 cutime:1 cstime: 3 | utime: 3 stime: 1 cutime:1 cstime: 3 | utime: 3 stime: 1 cutime:1 cstime: 3 | utime: 3 stime: 1 cutime:1 cstime: 3 $ while true; do true; done | utime: 49 stime: 1 cutime:1 cstime: 3 | utime: 137 stime: 1 cutime:1 cstime: 3 | utime: 209 stime: 1 cutime:1 cstime: 3 | utime: 296 stime: 1 cutime:1 cstime: 3 | utime: 391 stime: 1 cutime:1 cstime: 3 ^C | utime: 477 stime: 1 cutime:1 cstime: 3 | utime: 521 stime: 1 cutime:1 cstime: 3 | utime: 521 stime: 1 cutime:1 cstime: 3 | utime: 521 stime: 1 cutime:1 cstime: 3 $ bash | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 $ while true; do true; done | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 ^C | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 | utime: 522 stime: 1 cutime:1 cstime: 3 $ exit | utime: 522 stime: 1 cutime:623 cstime: 6 | utime: 522 stime: 1 cutime:623 cstime: 6 | utime: 522 stime: 1 cutime:623 cstime: 6 | utime: 522 stime: 1 cutime:623 cstime: 6 + utime: 522 stime: 1 cutime:623 cstime: 6 的新实例,并使用构造函数添加新项目:

List<Link>