Mid From PDF Coding Scenarios C# Coding Interview

Flatten a nested list?

List<object> list = new List<object> { 1, new List<int> { 2, 3 }, 4

};

List<int> result = new List<int>();

void Flatten(List<object> input)

{
foreach (var item in input)
{
if (item is int)

result.Add((int)item);

else

Flatten((List<object>)item);

}
}

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details