xxxxxxxxxx
static List<int?> ls = new List<int?>();
public static void Recursive(IList list)
{
if (list == null)
return;
foreach (var item in list)
{
if (item is int)
ls.Add(Convert.ToInt32(item));
else
Recursive(item as IList);
}
}
// this recursive function will do the job
xxxxxxxxxx
using System;
using System.Collections;
using System.Collections.Generic;
internal class RecursiveApproach
{
public static List<int?> ls = new List<int?>();
public static void Main()
{
ArrayList als = new ArrayList()
{
new ArrayList
{
1,
new int[]
{
2, 3, 4
},
new ArrayList
{
5, 6, 7, 8, 9
}
},
10,
new int[]{11,12,13},
14,
new ArrayList
{
15,
new int[]
{
16, 17,18
},
new ArrayList
{
19, 20,21, 22, 23
}
}
};
Recursive(als);
foreach (var i in ls)
{
Console.WriteLine(i);
}
}
public static void Recursive(IList list)
{
if (list == null)
{
return;
}
foreach (var item in list)
{
if (item is int)
{
ls.Add(Convert.ToInt32(item));
}
else
{
Recursive(item as IList);
}
}
}
}