ILOG CPLEX 11.0 User's Manual > Languages and APIs > ILOG Concert Technology for .NET Users > Good Programming Practices

The next steps of this tutorial show you how to add features to your application.

Step 16   -  

Read the command line (data from user)

Go to the comment Step 16 in Dietlesson.cs, and add the following lines to read the data entered by the user at the command line.

         for (int i = 0; i < args.Length; i++) {
            if ( args[i].ToCharArray()[0] == '-') {
               switch (args[i].ToCharArray()[1]) {
               case 'c':
                  byColumn = true;
                  break;
               case 'i':
                  varType = NumVarType.Int;
                  break;
               default:
                  Usage();
                  return;
               }
            }
            else {
               filename = args[i];
               break;
            }
         }
        
         Data data = new Data(filename);

Step 17   -  

Show correct use of command line

Go to the comment Step 17 in Dietlesson.cs, and add the following lines to show the user how to use the command correctly (in case of inappropriate input from a user).

   internal static void Usage() {
      System.Console.WriteLine(" ");
      System.Console.WriteLine("usage: Diet [options] <data file>");
      System.Console.WriteLine("options: -c  build model by column");
      System.Console.WriteLine("         -i  use integer variables");
      System.Console.WriteLine(" ");
   }

Step 18   -  

Enclose the application in try catch statements

Go to the comment Step 18 in Dietlesson.cs, and add the following lines to enclose your application in a try and catch statement in case of anomalies during execution.

      }
      catch (ILOG.CONCERT.Exception ex) {
         System.Console.WriteLine("Concert Error: " + ex);
      }
      catch (InputDataReader.InputDataReaderException ex) {
         System.Console.WriteLine("Data Error: " + ex);
      }
      catch (System.IO.IOException ex) {
         System.Console.WriteLine("IO Error: " + ex);
      }
   }

The try part of that try and catch statement is already available in your original copy of Dietlesson.cs. When you finish the steps of this tutorial, you will have a complete application ready to compile and execute.