Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. var myStrings = new [] {"Blackberry", "Rice", "Bacon", "Cocoa", "Meat"};
  9. var myChars = new [] {'a', 'e', 'b'};
  10.  
  11. var results = myStrings.Where(s => ContainsChar(s, myChars));
  12.  
  13. if (results.Any())
  14. {
  15. foreach(var item in results)
  16. {
  17. Console.WriteLine(item);
  18. }
  19. }
  20. else
  21. {
  22. Console.WriteLine("None Found");
  23. }
  24.  
  25. Console.ReadLine();
  26. }
  27.  
  28. public static bool ContainsChar(string str, char[] chars)
  29. {
  30. int strSameAsCharCount = 0;
  31.  
  32. foreach (char c in chars)
  33. {
  34. if(str.Contains(c))
  35. {
  36. strSameAsCharCount++;
  37. }
  38. }
  39.  
  40. if (strSameAsCharCount == chars.Length)
  41. {
  42. return true;
  43. }
  44. else
  45. {
  46. return false;
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement