Guest User

Untitled

a guest
Oct 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. using System.Linq;
  2.  
  3. namespace Alp
  4. {
  5. public static class Convert
  6. {
  7. /// <summary>
  8. /// Returns first string not empty. [ Alp.Convert.Coalesce(string.Empty, null, "test") returns "test" ]
  9. /// </summary>
  10. public static string Coalesce(params string[] strings) => strings.FirstOrDefault(s => !string.IsNullOrEmpty(s)) ?? string.Empty;
  11.  
  12. /// <summary>
  13. /// Returns first integer not zero. [ Alp.Convert.Coalesce(0, 10, 15) returns 10 ]
  14. /// </summary>
  15. public static int Coalesce(params int[] integers) => integers.FirstOrDefault(i => i != 0);
  16. }
  17. }
Add Comment
Please, Sign In to add comment