Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. public class ExampleClass
  2. {
  3. private static string[] words = new string[] { "Word1","Word2","Word3","Word4","Word5" };
  4.  
  5. public static bool IsExist(string Word)
  6. {
  7. return words.Any(w => w==Word);
  8. }
  9. }
  10.  
  11. ExampleClass.IsExist("Word1"); //Returns true
  12. ExampleClass.IsExist("WordNotExist"); //Returns false
  13.  
  14. ExampleClass.IsExist["Word1"]; //Returns true
  15. ExampleClass.IsExist["WordNotExist"]; //Returns false
  16.  
  17. public class ExampleClass
  18. {
  19. public class IsExistHelper
  20. {
  21. private static string[] words = new string[] { "Word1", "Word2", "Word3", "Word4", "Word5" };
  22.  
  23. public bool this[string Word]
  24. {
  25. get
  26. {
  27. return words.Any(w => w == Word);
  28. }
  29. }
  30. }
  31.  
  32. public static IsExistHelper IsExist { get; } = new IsExistHelper();
  33. }
  34.  
  35. public static class ExampleClass
  36. {
  37.  
  38. public class InnerIsExist
  39. {
  40. private string[] words = new string[] { "Word1", "Word2", "Word3", "Word4", "Word5" };
  41.  
  42. public bool this[string word]
  43. {
  44. get
  45. {
  46. return words.Contains(word);
  47. }
  48. }
  49. }
  50.  
  51. public static InnerIsExist IsExist { get; } = new IsExistClass();
  52. }
  53.  
  54. var doesItContain = ExampleClass.IsExist["b"]; // false
  55.  
  56. public class ExampleClass
  57. {
  58. private string[] words = new string[] { "Word1", "Word2", "Word3", "Word4", "Word5" };
  59.  
  60. public bool this[string Word]
  61. {
  62. get { return words.Any(w => w == Word); }
  63. }
  64. }
  65.  
  66. var _ = new ExampleClass();
  67. var isTrue = _["Word1"] == true
  68.  
  69. public static bool this[string Word]
  70. {
  71. get { return words.Any(w => w==Word); }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement