fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public class HelloClass
  7. {
  8. public int Value { get; set; }
  9. }
  10. public static void Main()
  11. {
  12. object[] test = new object[6];
  13. test[0] = "Hello,Ken";
  14. test[1] = 3.1415;
  15. test[2] = "Hello,Taro";
  16. test[3] = "Hi,Yoko";
  17. test[4] = 27182;
  18. test[5] = new HelloClass();
  19.  
  20. var xhellos =
  21. test
  22. .Where(o => o != null)
  23. .Select(o => o.ToString())
  24. .Where(o => o.Contains("Hello"))
  25. ;
  26.  
  27. var hellos =
  28. test
  29. .OfType<string>()
  30. .Where(o => o.Contains("Hello"))
  31. ;
  32.  
  33. foreach(var hello in hellos) {
  34. Console.WriteLine(hello);
  35. }
  36. }
  37. }
Success #stdin #stdout 0.04s 24016KB
stdin
Standard input is empty
stdout
Hello,Ken
Hello,Taro