Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExampleClass
- {
- private static string[] words = new string[] { "Word1","Word2","Word3","Word4","Word5" };
- public static bool IsExist(string Word)
- {
- return words.Any(w => w==Word);
- }
- }
- ExampleClass.IsExist("Word1"); //Returns true
- ExampleClass.IsExist("WordNotExist"); //Returns false
- ExampleClass.IsExist["Word1"]; //Returns true
- ExampleClass.IsExist["WordNotExist"]; //Returns false
- public class ExampleClass
- {
- public class IsExistHelper
- {
- private static string[] words = new string[] { "Word1", "Word2", "Word3", "Word4", "Word5" };
- public bool this[string Word]
- {
- get
- {
- return words.Any(w => w == Word);
- }
- }
- }
- public static IsExistHelper IsExist { get; } = new IsExistHelper();
- }
- public static class ExampleClass
- {
- public class InnerIsExist
- {
- private string[] words = new string[] { "Word1", "Word2", "Word3", "Word4", "Word5" };
- public bool this[string word]
- {
- get
- {
- return words.Contains(word);
- }
- }
- }
- public static InnerIsExist IsExist { get; } = new IsExistClass();
- }
- var doesItContain = ExampleClass.IsExist["b"]; // false
- public class ExampleClass
- {
- private string[] words = new string[] { "Word1", "Word2", "Word3", "Word4", "Word5" };
- public bool this[string Word]
- {
- get { return words.Any(w => w == Word); }
- }
- }
- var _ = new ExampleClass();
- var isTrue = _["Word1"] == true
- public static bool this[string Word]
- {
- get { return words.Any(w => w==Word); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement