fork download
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4.  
  5. class Example {
  6. static int k1=10, k2 = 5, k3 = 8, a = 8;
  7. static string k4 = "hello";
  8.  
  9. public static void Main() {
  10. try {
  11. var flds = typeof(Example).GetFields(
  12. BindingFlags.Static |
  13. BindingFlags.Public |
  14. BindingFlags.NonPublic
  15. ).Where(x => x.Name.StartsWith("k") /*&& x.FieldType==typeof(int)*/);
  16.  
  17. foreach(var f in flds) {
  18. Console.WriteLine("{0} = {1}", f.Name, f.GetValue(null));
  19. }
  20. }
  21.  
  22. catch(Exception ex) {
  23. Console.WriteLine(ex);
  24. }
  25.  
  26. }
  27. }
Success #stdin #stdout 0.04s 26660KB
stdin
Standard input is empty
stdout
k1 = 10
k2 = 5
k3 = 8
k4 = hello