Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class Test
  2. {
  3. static Test()
  4. {
  5. }
  6. }
  7.  
  8. using System;
  9. using System.Linq;
  10. using System.Reflection;
  11.  
  12. public class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. }
  17. }
  18.  
  19. public class Test
  20. {
  21. static Test()
  22. {
  23. ConstructorInfo ci = typeof(Test).GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Single();
  24. Console.WriteLine("Static constructor: IsPublic: {0}, IsPrivate: {1}", ci.IsPublic, ci.IsPrivate);
  25. }
  26. }
  27.  
  28. ildasm YourExe.exe /out:test.il
  29.  
  30. .entrypoint
  31. // Code size 2 (0x2)
  32. .maxstack 8
  33. IL_0000: nop
  34.  
  35. // we call manually the cctor (the static constructor)
  36. call void Test::.cctor()
  37. IL_0001: ret
  38.  
  39. .method public hidebysig specialname rtspecialname static
  40. void .cctor() cil managed
  41.  
  42. ilasm test.il
  43. test.exe
  44.  
  45. Static constructor: IsPublic: True, IsPrivate: False
  46. Static constructor: IsPublic: True, IsPrivate: False
  47.  
  48. //Static class with Access Modifier
  49. public class SomeClass
  50. {
  51. //Static Field with Access Modifier
  52. public static int intstatic = 0;
  53.  
  54. //Static Property with Access Modifier
  55. public static string StaticProperty { get; set; }
  56.  
  57. //Trying to declare static Constructor with Access Modifier
  58. public static SomeClass()
  59. { }
  60.  
  61. //Static Method with Access Modifier
  62. public static void DoSomething()
  63. {
  64. Console.WriteLine(intstatic);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement