public static int Main(string[] args)
        {
            /*
             * // If the AMPL installation directory is not in the system search path:
             * ampl.Environment env = new ampl.Environment(
             * "full path to the AMPL installation directory");
             * // Create an AMPL instance
             * using (AMPL a = new AMPL(env)) {}
             */

            // Create an AMPL instance
            using (var ampl = new AMPL())
            {
                ampl.Eval("var x{1..3};");
                ampl.Eval("maximize z: sum{i in 1..3} x[i];");

                // *** Output redirection *** Enable output redirection
                ampl.EnableOutputRouting();
                // Assign handler: Method 1: using method
                ampl.Output += HandleOutput;
                ampl.Eval("display x;");
                ampl.Eval("let {i in 1..3} x[i] := i;");
                ampl.Eval("display x;");
                // Unassign output handler
                ampl.Output -= HandleOutput;
                // print all outputs
                foreach (var t in outputs)
                {
                    Console.Write("{0} - Kind: {1} - Msg:\n{2}", t.Date,
                                  t.Kind, t.Msg);
                }

                // Method 2: Using lambda expression
                ampl.Output += (kind, message) => Console.Write("Got AMPL message:\n{0}\n", message);
                // Test it
                ampl.Eval("display x,x;");

                // *** Error redirection *** Enable error and warnings redirection
                ampl.EnableErrorAndWarningRouting();
                // Register handlers
                ampl.Error   += HandleError;
                ampl.Warning += HandleWarning;
                // Normally throws exception, will just be printed on screen
                ampl.Eval("var x;");
                // Create an obvious infeasibility
                ampl.Eval("c1: x[1]>=1; c2: x[1]<=0;");
                // Solve the model, issuing a warning
                ampl.Solve();
            }
            return(0);
        }