I want to know that How can I walk through this loop ?
this has a root
two chldren priv and nonpriv
and children of them for
priv:0,1,2,…,1023
and children of Nonpriv:
1024,..,65535
|Any______________PORT|
| |
|Priv| |Non-Priv|
|||||...|||| ||||....|||||
0123,.....1023 1024,...65535
I mean that 0 is in a distinct Node
1 is in a distinct Node
2 is in a distinct Node
these ports has parent PRIV
my reason of distincting them is that maybe some day 0 will have the list of children
they could be in a list and we can have a list of nodes or they could be in a list of strings but I can not decide what to do next about the list of string
and the problem with list of Node is in the for loop which I couldn’t build Nodes
Now I can’t configure the for loop how should I correct my code?
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);
}
}
}
}
You should use a collection to hold your objects, such as a list: