Skip to content

Instantly share code, notes, and snippets.

@bbqchickenrobot
Last active May 3, 2019 01:24
Show Gist options
  • Select an option

  • Save bbqchickenrobot/42c0c8e252c0d67ed67067c8ad0aaf75 to your computer and use it in GitHub Desktop.

Select an option

Save bbqchickenrobot/42c0c8e252c0d67ed67067c8ad0aaf75 to your computer and use it in GitHub Desktop.
FlattenJaggedArray
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var jagged = new object[]{
new object[]{
1, 2, new object[]{3}
}, 4
};
var flattend = new List<object>();
void flatten(object obj){
if(obj.GetType() == typeof(object[]))
{
foreach(var o in (object[])obj)
flatten(o);
}else{
flattend.Add(obj);
}
}
flatten(jagged);
foreach(var o in flattend)
Console.WriteLine(o);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment