fork download
  1. using static System.Console;
  2. using System;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. Teste(DateTime.Now);
  7. WriteLine();
  8. Teste("ok");
  9. }
  10.  
  11. public static void Teste(object qualquerVariavel) {
  12. if (qualquerVariavel is DateTime x) WriteLine($"A variável é DateTime e seu valor é {x.DayOfWeek}");
  13. if (qualquerVariavel is DateTime) WriteLine($"A variável é DateTime e seu valor é {((DateTime)qualquerVariavel).DayOfWeek}");
  14. if (qualquerVariavel is DateTime) //WriteLine($"A variável é DateTime e seu valor é {qualquerVariavel.DayOfWeek}"); //isto não compila
  15. if (qualquerVariavel is "ok") WriteLine($"A variável é string e vale ok");
  16. switch (qualquerVariavel) {
  17. case null:
  18. WriteLine("nulo");
  19. break;
  20. case int i:
  21. WriteLine(i);
  22. break;
  23. case string s:
  24. WriteLine(s);
  25. break;
  26. case DateTime d:
  27. WriteLine(d.DayOfWeek);
  28. break;
  29. }
  30. }
  31. }
  32.  
  33. //https://pt.stackoverflow.com/q/86493/101
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(15,24): error CS1644: Feature `pattern matching' cannot be used because it is not part of the C# 7.0 language specification
prog.cs(20,14): error CS0589: Internal compiler error during parsingSystem.NotImplementedException: type pattern matching
  at Mono.CSharp.CSharpParser.case_963 () <0x7fe8a77cd800 + 0x0007f> in <6d1f622b5bed41cf94a26e291798f831#da64574cc157543f8213a54ad5b33bb2>:0 
  at Mono.CSharp.CSharpParser.yyparse (Mono.CSharp.yyParser.yyInput yyLex) <0x7fe8a77a52c0 + 0x02096> in <6d1f622b5bed41cf94a26e291798f831#da64574cc157543f8213a54ad5b33bb2>:0 
  at Mono.CSharp.CSharpParser.parse () <0x7fe8a77d77a0 + 0x00069> in <6d1f622b5bed41cf94a26e291798f831#da64574cc157543f8213a54ad5b33bb2>:0 
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty