Faced with an interesting and not entirely clear behavior of the compiler.

Here is the code snippet:

static float Main(float[] args) { if (args.Length == 0) { Console.WriteLine("Неверное количество аргументов"); return 0f; } else { float _catA, _catB, _hypoC; try { DefinitionOfParties(args, out _catA, out _catB, out _hypoC); if (IsValidTriangle(_catA, _catB, _hypoC)) { return AreaCalculation(_catA, _catB); } return 0f; } catch (Exception ex) { Console.WriteLine(ex.Message); return 0f; } } } 

I try to add three numbers through the debug window, but I get an error on startup:

program doesn’t contain a static 'Main' method

It is not clear what VS wants from me? Swears at the lack of an entry point, which is?

  • one
    And where and to whom you want to return this value and who should pass the parameters to Main? - Andrei NOP
  • @ Andrei Generally, the task describes that it will be a plug-in library, but I don’t know how to work with such things - Garrus_En
  • I think I just answered my question. Thanks for the tip - Garrus_En
  • one
    Logically, the library should not have an entry point, so the project type is appropriate, and the studio will not require an entry point. Well, at the same time give the name of its normal function. - Andrei NOP

1 answer 1

Because the CLR cannot find the entry point. When executing a program written in C #, the CLR looks for the static Main method (but libraries and services do not require using the Main method as an entry point) marked IL (Intermediate Language) with the .entrypoint directive, which takes either no arguments or one argument of type string[] , and has a return type of void or int . Thus, such signatures are suitable:

 static void Main(); static void Main(string[] args); static int Main(); static int Main(string[] args);