What is the use of several basic methods?

C # allows us to define more than one class using a method. The main method is the entry point for executing the program. So why do we want to have more than one place to run the program. What is the advantage of several basic methods in one basic method.

Edit:

Example.cs

Class Example_1 { public static void Main() { System.Console.WriteLine("Example 1") } public void test() { System.Console.WriteLine("Test method") } } Class Example_2 { public static void Main() { System.Console.WriteLine("Example 2") } } 

If I find "csc Example.cs" then what will happen? What if I want to inherit the testing method of the Example_1 class in the Example_2 class. Will this code work.

 Example_1 abc = new Example_1(); abc.test(); 
+6
c #
source share
7 answers

You can use it so that different configurations build the same executable file, but with different entry points - for example, the entry point to the console and the entry point of WinForms.

Personally, I use it in negotiation and in the code example for C # in Depth. Each file is a self-contained example, but it’s easier to just have one entry point β€” so that the entry point uses the utility class to ask the user what example they should run for.

+12
source share

First, if you have several basic methods, you can specify which one to use as your entry point for the application by your compiler.

Several basic methods may be useful for testing purposes. Perhaps you are developing a Windows application such as a text editor. For example, if you are working on something like syntax highlighting, you can get an additional main method that launches the graphical user interface, loads a test file, and turns on the corresponding syntax highlighting. Another example would be an application that will only be compiled for use in the console or as a Windows application that includes two different classes with basic methods.

+5
source share

There can only be one entry point in a C # program. If you have more than one class that has a Main method, you should compile your program with the / main compiler option to indicate which main method to use as an entry point.

Compile t2.cs and t3.cs, indicating that the Main method will be found in Test2, like this,

csc t2.cs t3.cs / main: Test2

+1
source share

Different classes can use several methods called Main (). But only one of them is used to launch the program. This is the usual method, you can use a different Main for all that you want. (But this is not recommended.)

0
source share

This will probably be a rare occurrence, but I would suggest that if you had to reference some external code that the Main () method has, then you want to tell the compiler to use yours.

0
source share

Why don't you create multiple classes using the Main method? After all, Main is just the name of the method. If you create a class, it is quite normal to define a method named Main .

0
source share

When Using the Visual Studio CMD Command Prompt

Then try as follows:

 csc filename.cs /main:classname 

where filename is the name of the file in which the code is stored, and classname is the name of the class containing Main, which we would like to be an entry point.

As in this program, there are two classes A and B, in which each contains A Basic method. We can write how

csc filename.cs / main: A [for the main execution of class A] or

csc filename.cs / main: B [for the main execution of class B]

0
source share

All Articles