Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- IEnumerable<object> source = new object[] { new object[] { 1, 2, new object[] { 3 } }, 4 }; //[[1,2,[3]],4]
- IEnumerable<object> flatten(IEnumerable<object> s) => s?.SelectMany(x =>
- flatten(x as IEnumerable<object>) ?? new[] { x }
- );
- var result = flatten(source);
- result.ToList().ForEach(c =>
- {
- Console.WriteLine(c);
- });
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment