orilon

C# Extension Method - Coalesces strings (return first)

Jun 4th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.36 KB | None | 0 0
  1. /// <summary>
  2. /// Coalesces the specified strings.
  3. /// Example:
  4. ///     string result = Coalesce(s.SiteNumber, s.AltSiteNumber, "No Number");
  5. /// </summary>
  6. /// <param name="strings">The strings.</param>
  7. /// <returns></returns>
  8. private static string Coalesce(params string[] strings)
  9. {
  10.     return strings.Where(s => !s.IsNullOrEmpty()).FirstOrDefault();
  11. }
Advertisement
Add Comment
Please, Sign In to add comment