Why is the static void Main (line [] args) at the bottom of this program?

I study C #, and he says in the tutorial, “When you run your program, C # looks for the Main method. It uses the main method as a starting point for your programs. Then it runs any code between the two curly braces.”

But another training site has a code snippet that says

using System;
namespace RectangleApplication
{
   class Rectangle 
   {
     // member variables
     double length;
     double width;

     public void Acceptdetails()
     {
        length = 4.5;    
        width = 3.5;
     }

     public double GetArea()
     {
        return length * width; 
     }

     public void Display()
     {
        Console.WriteLine("Length: {0}", length);
        Console.WriteLine("Width: {0}", width);
        Console.WriteLine("Area: {0}", GetArea());
     }
   }

class ExecuteRectangle 
{
  static void Main(string[] args) 
     {
         Rectangle r = new Rectangle();
         r.Acceptdetails();
         r.Display();
         Console.ReadLine(); 
      }
   }
}

Using the Main method below other methods. (I am new to this, so I assume that public void acceptdetails, get scope, mapping, all methods). My question is: why is it not in the upper right of the namespace? I put the method there, and it worked the same way and checked other posts here, and he said that maybe the author was just trying to focus on other things, but I don’t quite understand why.

+4
3

, . Main() , . , Main(), , , , .

, Main() , .

+5

Main() - "" , , . Rectangle, , . Main() . , .

+2

, , # , . , , , . , . "" . , . "" , .

, . , , , , .

Therefore, as you can see, no matter where you put your code in your code files, the compiler does the string building anyway.

Of course, I omitted the extended cases of concurrent programming or asynchronous operations.

0
source

Source: https://habr.com/ru/post/1583905/


All Articles