[英]How to pass two function to another function with a delegate for parameters in C#
[英]How to pass parameters to another process in c#
我剛剛創建了一個使用以下代碼啟動進程的應用程序
string [] args = {"a", "b"};
Process.Start ("C: \ \ demo.exe" String.Join ("", args));
我希望能夠將參數從此應用程序傳遞給我啟動的過程。
在啟動過程的項目中必須在哪里輸入參數? 我試圖把它們放進去
static void Main (string [] args) {...
但無法以其他形式使用。 謝謝您的幫助
Process p= new Process();
p.StartInfo.FileName = "demo.exe";
p.StartInfo.Arguments = "a b";
p.Start();
要么
Process.Start("demo.exe", "a b");
在demo.exe中
static void Main (string [] args)
{
Console.WriteLine(args[0]);
Console.WriteLine(args[1]);
}
您問如何保存這些參數。 您可以創建具有靜態屬性的新類,然后將這些參數保存在那里。
class ParamHolder
{
public static string[] Params { get; set;}
}
和主要
static void Main (string [] args)
{
ParamHolder.Params = args;
}
在程序的任何位置獲取參數:
Console.WriteLine(ConsoleParamHolder.Params[0]);
Console.WriteLine(ConsoleParamHolder.Params[1]);
等等
主要應用代碼:
var process = new Process();
process.StartInfo.FileName = "demo.exe" // Path to your demo application.
process.StartInfo.Arguments = "a b c" // Your arguments
process.Start();
在您的演示應用程序中(我假設這是控制台應用程序)
static void Main (string [] args)
{
var agrumentOne = args[0];
var agrumentTwo = args[1];
var agrumentThree = args[3];
}
這里argumentsOne,argumentTwo,argumentThree將包含“ a”,“ b”和“ c”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.