如何发送2-3参数对WinForm的C#程序? [英] how to send 2-3 param's to Winform C# program?

查看:113
本文介绍了如何发送2-3参数对WinForm的C#程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何发送2-3参数对WinForm的C#程序

how to send 2-3 param's to Winform C# program ?

例如:我会送东西像 10 MYPROG.EXE 20 ABC

和在我的计划,我可以接受这些值

and in my program i can receive those values

(我不希望显示MYPROG.EXE - 它会工作背景)

(i dont want to show MyProg.exe - it will work background)

感谢的提前

推荐答案

打开你的的Program.cs 这是应用程序的入口点。其主要方法是触发了您的应用程序之一,这是输入法

Open up your Program.cs which is the entry point of your application. The main method is the one that fires up your application and this is the entry method.

您需要通过chaning修改了一点:

You need to modify it a bit by chaning:

静态无效的主要()来别的东西,可以让你发送阵列 。元素

static void Main() to something else that will allow you to send an array of elements.

尝试将其更改为:

静态无效的主要(字符串[ ]参数)并通过ARGS循环,看看你会得到什么。

static void Main(string[] args) and loop through args and see what you get.

您可以看到在这里多一点的例子和explenations:的访问命令行参数的。

You can see a bit more examples and explenations over here: Access Command Line Arguments.

有好的库,这将使有点帮助你出去解析这些命令行参数以及。

There are good libraries which will help you out a bit to parse these command line arguments aswell.

例子

为了让你多一点信息我放在一起的例子的一种替代方式了Kobi提到的:

To give you a bit more information I put together an example on an alternative way as Kobi mentioned:

class Program
{
    static void Main()
    {
        ParseCommnandLineArguments();
    }

    static void ParseCommnandLineArguments()
    {
        var args = Environment.GetCommandLineArgs();

        foreach(var arg in args)
            Console.WriteLine(arg);
    }
}



CommandLineArguments.exe -qa -br

将输出

CommandLineArguments .EXE

CommandLineArguments.exe

-q

-b

研究

同样的结果也有可能与该方法

The same result would also be possible with this way

class Program
{
    static void Main(string[] args)
    {
        foreach (var arg in args)
            Console.WriteLine(arg);
    }
}

这篇关于如何发送2-3参数对WinForm的C#程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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