fork download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8.  
  9.  
  10. public static void Main()
  11. {
  12. int[] numbers = { 5, 2, 1, 5 };
  13. string[] words = { "flibble", "bobble", "double", "dumble" };
  14.  
  15. IEnumerable<string> result = numbers
  16. .Select((len, i) => {
  17. string word = words.ElementAtOrDefault(i);
  18. if (word != null)
  19. {
  20. word = word.Length >= len ? word.Substring(0, len) : word;
  21. }
  22. return word;
  23. });
  24. Console.Write(String.Join(",",result.ToArray()));
  25. }
  26. }
Success #stdin #stdout 0.03s 33968KB
stdin
Standard input is empty
stdout
flibb,bo,d,dumbl