110,566
社区成员
发帖
与我相关
我的任务
分享
foreach(string Argument in Arr)
{
Response.Write(Argument); //在web控制台,输出每个参数
}
string[] Arr= Environment.GetCommandLineArgs();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace 命令行
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args) //要加上传入参数,默认是没有的
{
if (args.Length == 0) //如果没有参数传入
{
args = new string[] { "a", "b", "c" }; //则指定为默认值
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(args)); //传递给窗体
}
}
}
Form1.csusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 命令行
{
public partial class Form1 : Form
{
public Form1(string[] args) //要加上传入参数,默认是没有的
{
InitializeComponent();
label1.Text = string.Join("\n", args); //对传入的参数做些处理
}
}
}
static void Main(string[] args)
{
if (args.Length == 0)
{
args = new string[] { "a", "b", "c" };
}
static void Main(string[] args)
{
string param1 = "defaultValue1";
string param2 = "defaultValue2";
if (args != null && args.Length >= 2)
{
param1 = args[0];
param1 = args[1];
}
//use your param
}