Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- namespace Alp
- {
- public static class Convert
- {
- /// <summary>
- /// Returns first string not empty. [ Alp.Convert.Coalesce(string.Empty, null, "test") returns "test" ]
- /// </summary>
- public static string Coalesce(params string[] strings) => strings.FirstOrDefault(s => !string.IsNullOrEmpty(s)) ?? string.Empty;
- /// <summary>
- /// Returns first integer not zero. [ Alp.Convert.Coalesce(0, 10, 15) returns 10 ]
- /// </summary>
- public static int Coalesce(params int[] integers) => integers.FirstOrDefault(i => i != 0);
- }
- }
Add Comment
Please, Sign In to add comment