Did you ever wondered what it would be like if you are not limited to static Main(string[] args) as your entrypoint? Did you ever wanted more freedom over where your app starts? Actually you can have that.But in order to do it – you need to go one level lower. Into an IL level. In the last post from this series – you got some knowledge about basic tooling. Here we will see how to make something with them.
If you decompile your app to IL you will notice that on the Main method there’s a directive .entrypoint. This what specifies where the app will start. It is placed automatically by the C# compiler. But if we can – we can move it.
Just remove it and paste it in any other static method. Compile (ILASM) & run. It works like a charm. If you try to do the same with non-static method – you will get an error during ilasm-ing your code.
This is a nice little trick that can use on your .NET guru friends to check their knowledge. Have fun.
Founder of Octal Solutions a .NET software house.
Passionate dev, blogger, occasionally speaker, one of the leaders of Wroc.NET user group. Microsoft MVP. Podcaster – Ostrapila.pl