D
D
Denis Bredun2020-07-27 01:54:01
C++ / C#
Denis Bredun, 2020-07-27 01:54:01

How does the compiler understand that the first function to be called will be Main()?

class Program
{
  public static void Main(string [] args)
  {

  }
  public static void DoSomething()
  {

  }
}

Why does the compiler call Main and not DoSomething? Main in the method table is somehow marked in a special way? How does he understand that it is necessary to call her?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris the Animal, 2020-07-27
@Luffy1

In the book CLR via C# - Programming on the Microsoft.NET Framework 4.5 in C#. 4th Edition on page 37 in the chapter Executing assembly code says:

Next, the main thread calls the method defined in the MSCorEE.dll library, which initializes the CLR, loads the EXE assembly, and then calls its Main method, which contains the entry point. This completes the procedure for launching a managed application.

It is also written in the Microsoft documentation that it is the Main method that is called if the name of another method is not passed as the -main compiler parameter.
Microsoft Documentation:
Main() and Command Line Arguments
Starting the Application

R
Roman, 2020-07-27
@yarosroman

My answer is the simplest, I don't care. Well, you have to, well, okay. If, for example, understanding how the GC works still affects something, then it doesn’t. And it's not even interesting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question