fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication3
  7. {
  8. //拡張メソッドを定義するクラスはstaticにさえしておけば、どんな名前にしてもいいよ!Class名は飾りだよ
  9. static class OresamanoTukuttaExtendMethods
  10. {
  11. public static bool In(this string input, params string[] others)
  12. {
  13. return others.AsEnumerable().Any(a => a == input);
  14. }
  15. }
  16.  
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21. string s1 = "TEST";
  22. string[] ss1 = new string[] {"aaa","bbb","ccc" };
  23. Console.WriteLine("{0}に等しい文字がss1配列にあるか?{1}", s1, s1.In(ss1));
  24.  
  25. string[] ss2 = new string[] { "aaa", "TEST", "ccc" };
  26. Console.WriteLine("{0}に等しい文字がss2配列にあるか?{1}", s1, s1.In(ss2));
  27.  
  28. }
  29. }
  30. }
  31.  
Success #stdin #stdout 0.04s 36952KB
stdin
Standard input is empty
stdout
TEST???????ss1???????False
TEST???????ss2???????True