如何将命令行参数传递给 WinForms 应用程序? [英] How do I pass command-line arguments to a WinForms application?

查看:36
本文介绍了如何将命令行参数传递给 WinForms 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的 WinForms 应用程序,AppA 和应用 B.两者都运行 .NET 2.0.

I have two different WinForms applications, AppA & AppB. Both are running .NET 2.0.

在 AppA 中,我想打开 AppB,但我需要将命令行参数传递给它.如何使用我在命令行中传递的参数?

In AppA I want to open AppB, but I need to pass command-line arguments to it. How do I consume the arguments that I pass in the command line?

这是我目前在 AppB 中的主要方法,但我认为你不能改变这个?

This is my current main method in AppB, but I don't think you can change this?

  static void main()
  {
  }

推荐答案

static void Main(string[] args)
{
  // For the sake of this example, we're just printing the arguments to the console.
  for (int i = 0; i < args.Length; i++) {
    Console.WriteLine("args[{0}] == {1}", i, args[i]);
  }
}

参数将存储在 args 字符串数组中:

The arguments will then be stored in the args string array:

$ AppB.exe firstArg secondArg thirdArg
args[0] == firstArg
args[1] == secondArg
args[2] == thirdArg

这篇关于如何将命令行参数传递给 WinForms 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆