Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. string str = "1,2,3;2,3,4;4,5,6";
  2. var arr = str
  3. .Split(';')
  4. .Select(x => x.Split(','))
  5. .Select(x => new
  6. {
  7. first = x[0],
  8. second = x[1],
  9. third = x[2]
  10. })
  11. .ToList();
  12.  
  13. Enumerable.WhereSelectArrayIterator<string, <>f__AnonymousType0#10<string, string, string>> { { first = "1", second = "2", third = "3" }, { first = "2", second = "3", third = "4" }, { first = "4", second = "5", third = "6" } }
  14.  
  15. List<string>(3) { "1t2t3", "2t3t4", "4t5t6" }
  16.  
  17. arr.Select(x => x.first + "t" + x.second + "t" + x.third).ToList();
  18.  
  19. arr.Select(x => x.first, x.second, x.third).ToList();
  20.  
  21. public static IEnumerable<string> JoinByTab<T>(this IEnumerable<T> list) where T : class
  22. {
  23. PropertyInfo[] properties = list.FirstOrDefault().GetType().
  24. GetProperties(BindingFlags.Public | BindingFlags.Instance);
  25.  
  26. var listStr = list
  27. .Select(x => String.Join("t", properties.Select(y => y.GetValue(x, null).ToString())));
  28.  
  29. return listStr;
  30. }
  31.  
  32. public static IEnumerable<string> Join<T>(this IEnumerable<T> list,
  33. string separator,
  34. params Func<T, string>[] properties) where T : class
  35. {
  36. foreach (var element in list)
  37. {
  38. yield return string.Join(separator, properties.Select(p => p(element)));
  39. }
  40. }
  41.  
  42. var result = arr.Join("t",
  43. x => x.first,
  44. x => x.second,
  45. x => x.third)
  46. .ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement