In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to upload parameters to the Main method, I believe many inexperienced people are helpless about this, this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.
Parameters can be sent to the Main method by defining the method in one of the following ways.
static int Main(string[] args)
static void Main(string[] args)
Note: To enable command-line arguments in the Main method in Windows Forms applications, you must manually modify the signature of Main in program.cs. The code generated by Windows Forms Designer creates Main with no input parameters. You can also use Environment.CommandLine or Environment.GetCommandLineArgs to access command-line parameters from anywhere in the console or Windows application.
The arguments to the Main method are String arrays representing command-line arguments. Generally, it is determined whether the parameter exists by testing the Length attribute, for example:
if (args.Length == 0) { WriteLine("Hello World. "); return 1; }
You can also use the Convert class or Parse method to convert string arguments to numeric types. For example, the following statement converts a string to a long number using the Parse method:
long num = Int64.Parse(args[0]);
You can also use C#type long with alias Int64:
long num = long.Parse(args[0]);
You can also use Convert class method ToInt64 to do the same thing:
long num = Convert.ToInt64(s);
example
The following example demonstrates how to use command-line arguments in a console application. The application takes a parameter at runtime, converts it to an integer, and calculates the factorial of that number. If no arguments are provided, the application issues a message explaining the correct usage of the program.
public class Functions { public static long Factorial(int n) { if ((n
< 0) || (n >20)) { return -1; } long tempResult = 1; for (int i = 1; i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.