将快捷方式的信息传递给c#.exe

时间:2013-02-13 10:56:57

标签: c# .net wpf

我有一个wpf c#项目,我希望以其他编码员看到的方式传递一些启动信息信息,只看他们的捷径

所以我看到的捷径是:

  

X:\ Test.exe / host = [服务器位置] / instance = 0 / coid =%coid / userid =%oper

我理解传递的是什么,但我想了解c#项目如何以粗体显示信息,我想将其分配给字符串等。

我试图谷歌信息,但我不知道该怎么称呼主题

任何帮助 - 即使是不能做到这一点也会有所帮助

3 个答案:

答案 0 :(得分:2)

请参阅MSDN上的Command Line Parameters Tutorial

应用程序有一个入口点,在这种情况下为public static void Main(string[] args)args参数包含命令行参数,按空格分割。

编辑:我的不好,不知道WPF是令人讨厌的。看看这里:WPF: Supporting command line arguments and file extensions

protected override void OnStartup(StartupEventArgs e)
{
    if (e.Args != null && e.Args.Count() > 0)
    {
        this.Properties["ArbitraryArgName"] = e.Args[0];
    }

    base.OnStartup(e);
}

答案 1 :(得分:0)

您可以使用

将命令行参数检索到string[]
string[] paramz = Environment.GetCommandLineArgs();

答案 2 :(得分:0)

在此示例中,程序在运行时接受一个参数,将参数转换为整数,并计算数字的阶乘。如果没有提供参数,程序会发出一条消息,说明程序的正确用法。

public class Functions
    {
        public static long Factorial(int n)
        {
            if (n < 0) { return -1; }    //error result - undefined
            if (n > 256) { return -2; }  //error result - input is too big

            if (n == 0) { return 1; }

            // Calculate the factorial iteratively rather than recursively:

            long tempResult = 1;
            for (int i = 1; i <= n; i++)
            {
                tempResult *= i;
            }
            return tempResult;
        }
}

class MainClass
{
    static int Main(string[] args)
    {
        // Test if input arguments were supplied:
        if (args.Length == 0)
        {
            System.Console.WriteLine("Please enter a numeric argument.");
            System.Console.WriteLine("Usage: Factorial <num>");
            return 1;
        }

        try
        {
            // Convert the input arguments to numbers:
            int num = int.Parse(args[0]);

            System.Console.WriteLine("The Factorial of {0} is {1}.", num, Functions.Factorial(num));
            return 0;
        }
        catch (System.FormatException)
        {
            System.Console.WriteLine("Please enter a numeric argument.");
            System.Console.WriteLine("Usage: Factorial <num>");
            return 1;
        }
    }
}

输出为The Factorial of 3 is 6.此应用程序的使用方式类似于Factorial.exe <num>

相关问题