Graduate Business Software Development Path-Main Function

Source: Internet
Author: User

Recently, I began to contact students, college interns and graduates. I would like to talk about some suggestions for these students wandering in the workplace, hoping to help these beginners enter the software development industry, this allows graduates to enter the software development company more smoothly to start their career and make a perfect turn in their life.
----------------------------------------------------------------
Main Function
The Windows application and command line program in C # are compiled with the EXE file, which is the entry point for defining the Startup Program. This entry point is the main function in C #, which is similar to the C language.
In the C # project of the "first Windows application", a source code file of "Program. cs" is included. The content of the file is as follows. [Yuan Yongfu copyright]
 
Using System;
Using System. Collections. Generic;
Using System. Windows. Forms;

Namespace: The first Windows Application
{
StaticclassProgram
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Staticvoid Main ()
{
Application. EnableVisualStyles ();
Application. SetCompatibleTextRenderingDefault (false );
Application. Run (newForm1 ());
}
}
}
This file defines the Main function. a c # Windows application or command line program has only one Main function. [Yuan Yongfu copyright]
The Code "[STAThread]" before the Main function notifies the compiler that the function adopts the single-threaded mode.
Here, the Main function does not define parameters and return values. In fact, the Main function can define a return value of the int type and a parameter of the string array type, for example, "int Main (string [] args)" to obtain command line parameters. Generally, Windows applications with graphical user interfaces do not need to support command line parameters, however, command line applications rely on command line parameters to call functions.
In addition to obtaining command line parameters in the Main function, developers can use the System type anywhere. the CommandLine static attribute of Environment obtains the command line text used by the startup program. You can also use the GetCommandLineArgs static method to obtain the command line parameters used by the Startup Program.
The command is a string. For example, on the Windows command line interface, run the command "c: \ my.exe *. jpg \ a \ s. The value of the CommandLine attribute of the Environment type is "c: \ my.exe *. jpg \ a \ s ", and its GetCommandLineArgs method returns a string array with four elements. The array values are" c: \ my.exe "and" *. jpg, \ a, and \ s ".
The Code "Application. EnableVisualStyles ()" in the Main function enables the entire Application to start the XP style.
When the Windows application starts the XP style, the user interface is displayed as shown in. [Yuan Yongfu copyright]

If the XP style is not enabled, the user interface is displayed, as shown in.

The Code "Application. Run (newForm1 ()" in the Main function is to create a form object and Run the form. This function is synchronized. As long as the form is not closed, the function will not return. When the form is closed, the function returns, and there is no code after the Main function, so the program exits. [Yuan Yongfu copyright]
This article is from the "Nanjing yuan Yongfu" blog

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.