Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test
- {
- static Test()
- {
- }
- }
- using System;
- using System.Linq;
- using System.Reflection;
- public class Program
- {
- static void Main(string[] args)
- {
- }
- }
- public class Test
- {
- static Test()
- {
- ConstructorInfo ci = typeof(Test).GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Single();
- Console.WriteLine("Static constructor: IsPublic: {0}, IsPrivate: {1}", ci.IsPublic, ci.IsPrivate);
- }
- }
- ildasm YourExe.exe /out:test.il
- .entrypoint
- // Code size 2 (0x2)
- .maxstack 8
- IL_0000: nop
- // we call manually the cctor (the static constructor)
- call void Test::.cctor()
- IL_0001: ret
- .method public hidebysig specialname rtspecialname static
- void .cctor() cil managed
- ilasm test.il
- test.exe
- Static constructor: IsPublic: True, IsPrivate: False
- Static constructor: IsPublic: True, IsPrivate: False
- //Static class with Access Modifier
- public class SomeClass
- {
- //Static Field with Access Modifier
- public static int intstatic = 0;
- //Static Property with Access Modifier
- public static string StaticProperty { get; set; }
- //Trying to declare static Constructor with Access Modifier
- public static SomeClass()
- { }
- //Static Method with Access Modifier
- public static void DoSomething()
- {
- Console.WriteLine(intstatic);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement