Skip to content

Instantly share code, notes, and snippets.

@vertigra
Last active February 1, 2017 04:43
Show Gist options
  • Save vertigra/e7ae461687c2518699a01896e4164b78 to your computer and use it in GitHub Desktop.
Save vertigra/e7ae461687c2518699a01896e4164b78 to your computer and use it in GitHub Desktop.
Запуск программы с параметрами (С#)

Запуск программы с параметрами (С#)

Простой пример

В Program.cs

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(args));
        }
    }

    

В Form1.cs

public partial class Form1 : Form
   {
       private string[] mArgs;

       public Form1(string[] args)
       {
           //test run parametr cmd
           this.mArgs = args;
           InitializeComponent();

           if (args.Length > 0)
           {
               MessageBox.Show(args[0]);
           }
       }
    }

Запуск

> program.exe test

Выведет MessageBox с сообщением test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment