SHARE
TWEET

Untitled

a guest Jun 27th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. List<string> names = new List<string>() { "John", "Anna", "Monica" };
  2. var result = String.Join(", ", names.ToArray());
  3.      
  4. var names = new List<string>() { "John", "Anna", "Monica" };
  5. var joinedNames = names.Aggregate((a, b) => a + ", " + b);
  6.      
  7. List<string> targets = new List<string>();
  8.  
  9. var InboxChecked = true;
  10. var BannerChecked = false;
  11. var EmailChecked = true;
  12.  
  13. if (InboxChecked)
  14. {
  15.     targets.Add("Inbox");
  16. }
  17.  
  18. if (BannerChecked)
  19. {
  20.     targets.Add("Banner");
  21. }
  22.  
  23. if (EmailChecked)
  24. {
  25.     targets.Add("Email");
  26. }
  27.  
  28. var index = 0;
  29.  
  30. if (targets.Any())
  31. {
  32.     var aggregate = targets.Aggregate((s1, s2) =>
  33.     {
  34.         return ++index == targets.Count - 1 ? s1 + " and " + s2 : s1 + ", " + s2;
  35.     });
  36.  
  37.     // aggregate.Dump();
  38. }
  39.  
  40. // returns -> Inbox and Email
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top