开发者

how i can run infinite loop in c#

i want to run a infinite loop in c#. the structure i have is hirachical means every index have a list of same strucutre.

the thing look like

a person have their two child maybe the two child have two the loop is infinite how i can run them on aspx page.

any suggestion to do that

public str开发者_如何学Gouct mystruct{
public int ID;
public List<mystruct> childs
}


A proper recursive graph is not really possible with structs; you would need to change to a class:

public class MyType{
    public int ID {get;set;}
    private readonly List<MyType> children = new List<MyType>();
    public List<MyType> Children {get{return children;}}
}

The problem is that otherwise virtually every time you try to mutate them to create the cycle, you get a copy, not the same instance.

Since this is a mutable entity type, it should be a class anyway.

Then even something as simple as:

var obj = new MyType();
obj.Children.Add(obj);

is a recursive graph.


CheckMyStruct(myStruct aStruct)
{
   doSomethingWithStruct(aStruct);
   if(aStruct.childs != null)
   { 
        foreach(myStruct aChild in aStruct.Childs)
            {
               CheckMyStruct(aChild);
            }
   }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜