Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. int[] arr = new int[5] {1,2,3,4,5};
  2.  
  3. string => "1,2,3,4,5"
  4.  
  5. var result = string.Join(",", arr);
  6.  
  7. public static string Join<T>(string separator, IEnumerable<T> values);
  8.  
  9. string.Join(",", arr)
  10.  
  11. string.Join(",", Array.ConvertAll(arr, x => x.ToString()))
  12.  
  13. public static string ToDelimitedString<T>(this IEnumerable<T> lst, string separator = ", ")
  14. {
  15. return lst.ToDelimitedString(p => p, separator);
  16. }
  17.  
  18. public static string ToDelimitedString<S, T>(this IEnumerable<S> lst, Func<S, T> selector,
  19. string separator = ", ")
  20. {
  21. return string.Join(separator, lst.Select(selector));
  22. }
  23.  
  24. new int[] { 1, 2, 3, 4, 5 }.ToDelimitedString();
  25.  
  26. int[] arr = new int[5] {1,2,3,4,5};
  27.  
  28. String arrTostr = arr.Select(a => a.ToString()).Aggregate((i, j) => i + "," + j);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement