Skip to content

Instantly share code, notes, and snippets.

@ajpinedam
Created July 14, 2014 16:02
Show Gist options
  • Save ajpinedam/9adf05512d94fb7744e8 to your computer and use it in GitHub Desktop.
Save ajpinedam/9adf05512d94fb7744e8 to your computer and use it in GitHub Desktop.
PrintList
using System;
using System.Collections.Generic;
namespace PrintList
{
public class Program
{
static void Main(string[] args)
{
PrintList("Mono", new List<object>
{
"Red", new List<Object>{"Yellow", "Green", "Blue"}, "Black", new List<Object>{new List<Object>{"Orange", "Purple"}, "White"}
});
Console.ReadLine();
}
private static void PrintList(string linePrefix, List<Object> list)
{
int mainIndex = 0;
if (list == null || list.Count == 0)
{
Console.WriteLine("No values to print...");
return;
}
foreach (var t in list)
{
var newPrefix = linePrefix + "." + mainIndex;
if (t as String != null)
{
Console.WriteLine("{0}: {1}", newPrefix, t.ToString());
}
else if (t as List<Object> != null)
{
PrintList(newPrefix, t as List<Object>);
}
else
{
Console.WriteLine("{0} : {1} - {2}", newPrefix, "Not a valid type", t.GetType());
}
mainIndex++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment