ListStringExtensin.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace SiwiFms.Helper
  6. {
  7. public static class ListStringExtensin
  8. {
  9. /// <summary>
  10. /// 转换为逗号隔开的字符串
  11. /// </summary>
  12. /// <param name="list"></param>
  13. /// <returns></returns>
  14. public static string ToArrayString(this List<string> list,string jg = ",")
  15. {
  16. if (list.Count == 0) return "";
  17. string returnstr = "";
  18. foreach (string str in list)
  19. {
  20. if (str == null||string.IsNullOrWhiteSpace(str)) continue;
  21. returnstr += (str + jg);
  22. }
  23. if (returnstr.Length == 0)
  24. {
  25. return returnstr;
  26. }
  27. else
  28. {
  29. return returnstr.Substring(0, returnstr.Length - jg.Length);
  30. }
  31. }
  32. public static object[] ToArrayObject(this List<string> list) {
  33. object[] objs = new object[] { };
  34. if (list.Count == 0) return objs;
  35. return list.ToArray();
  36. }
  37. }
  38. }