CollectionHelper.cs 977 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace IES.ExamServer.Helpers
  2. {
  3. public static class CollectionHelper
  4. {
  5. /// <summary>
  6. /// 判断集合是否为空
  7. /// </summary>
  8. /// <param name="collection"></param>
  9. /// <returns></returns>
  10. public static bool IsEmpty<T>(this IEnumerable<T>? collection)
  11. {
  12. if (collection != null && collection.Any())
  13. {
  14. return false;
  15. }
  16. else
  17. {
  18. return true;
  19. }
  20. }
  21. /// <summary>
  22. /// 判断集合是否不为空
  23. /// </summary>
  24. /// <param name="collection"></param>
  25. /// <returns></returns>
  26. public static bool IsNotEmpty<T>(this IEnumerable<T>? collection)
  27. {
  28. if (collection != null && collection.Any())
  29. {
  30. return true;
  31. }
  32. else
  33. {
  34. return false;
  35. }
  36. }
  37. }
  38. }