我想知道我该如何走过这个循环? 这有一个根 2 chldren私法和他们的nonpriv 和儿童 私法:0,1,2,...,1023 和Nonpriv的孩子: 1024,...,65535是否有可能在循环中构建并新建一个结构?
|Any______________PORT|
| |
|Priv| |Non-Priv|
|||||...|||| ||||....|||||
0123,.....1023 1024,...65535
我的意思是0是在不同的节点 1是在不同的节点 2是在不同的节点 这些端口具有父PRIV 我的理由distincting他们的是,也许有一天0将来有了孩子
名单他们可能在一个列表中,我们可以有一个节点列表或他们可以在一个字符串列表,但我不能决定接下来做什么关于字符串列表 和节点列表问题是在我无法建立的for循环节点
现在我不能配置for循环我应该如何纠正我的代码?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IDS
{
class Program
{
static void Main(string[] args)
{
Node root = new Node("Any_PORT");
List<Node> portcat = new List<Node>();
Node Priv = new Node("Priv");
Node NonPriv=new Node("Non-Priv");
root.setchildren(portcat);
root.Thisisroot();
root.setNodeinlist(Priv);
root.setNodeinlist(NonPriv);
Priv.setparent(root);
NonPriv.setparent(root);
List<Node> portsP = new List<Node>();
Priv.setchildren(portsP);
for (int i = 0; i < 1024; i++)
{
}
//I tried this one but I can't fix between Nodes and list of a string
List<string> portsN = new List<string>();
for (int i = 1024; i < 65535; i++)
{
portsN.Add(i.ToString());
}
}
public class Node
{
public string Data;
public List<Node> Children = new List<Node>();
public Node parent;
public Node(string r)
{
this.Data = r;
}
public Node Thisisroot()
{
this.parent = null;
return this;
}
public void setchildren(List<Node> list)
{
this.Children = list;
}
public List<Node> getchildren()
{
return this.Children;
}
public void setparent(Node p)
{
this.parent = p;
}
public Node getparent()
{
return this.parent;
}
public void setNodeinlist(Node n)
{
this.Children.Add(n);
}
}
}
}
看起来像是想使用'List'并添加到该列表中。另外,我鼓励您在提问之前先阅读C#教程。 –
BrokenGlass
2012-04-08 18:44:31
您需要'列表'而不是'列表',请参阅我的答案。 –
sll
2012-04-08 18:49:56
@Negin Nicki:是“错误,我是一个愚蠢的?!”您收到的实际错误消息?如果没有,你可以发布实际的错误信息吗?如果您阅读它们,修复错误通常会更容易,并且只有在发布实际消息时我们才能做到这一点。 – 2012-04-08 18:51:29