Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have tested and written up a complete console program that should work. Here you go:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { public interface ITest { int val {get; set; } List&lt;ITest&gt; Tests {get; set; } } public class Test1 : ITest { public int val { get; set; } public List&lt;ITest&gt; Tests {get; set; } public Test1() { Tests = new List&lt;ITest&gt;(); } } public class Test2 : ITest { public int val { get; set; } public List&lt;ITest&gt; Tests {get; set; } public Test2() { Tests = new List&lt;ITest&gt;(); } } public class Test3 : ITest { public int val { get; set; } public List&lt;ITest&gt; Tests {get; set; } public Test3() { Tests = new List&lt;ITest&gt;(); } } public class Test4 : ITest { public int val { get; set; } public List&lt;ITest&gt; Tests { get { return new List&lt;ITest&gt;(); } set {} } } class Program { public static int GetMinVal(ITest initialTest, out ITest testWithMinVal) { int minVal = initialTest.val; testWithMinVal = initialTest; foreach (ITest t in initialTest.Tests) { if (t.val &lt; minVal) { minVal = GetMinVal(t, out testWithMinVal); } } return minVal; } static void Main(string[] args) { Random r = new Random(); Test1 test = new Test1(); test.val = r.Next(100); for (int i = 0; i &lt; 5; i++) { Test2 test2 = new Test2(); test2.val = r.Next(100); for (int j = 0; j &lt; 4; j++) { Test3 test3 = new Test3(); test3.val = r.Next(100); for (int k = 0; k &lt; 3; k++) { Test4 test4 = new Test4(); test4.val = r.Next(100); test3.Tests.Add(test4); } test2.Tests.Add(test3); } test.Tests.Add(test2); } ITest testA; int minVal = GetMinVal(test, out testA); Console.WriteLine(minVal); } } } </code></pre> <p>I hope this helps...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload