.NET Interface (C#)

This section assumes that you are already familiar with the C# programming language. If not, a variety of books and websites are available for learning the language (for example, the Microsoft online C# documentation).

While C# programs have historically only run on Windows machines, Microsoft has recently released an open-source, cross-platform .NET implementation (.NET Core) that allows you to run C# programs on Linux and Mac OS as well. You will find the Gurobi library that supports .NET Core 2 in <installdir>/lib/gurobi91.netstandard20.dll. For more information on how to obtain and use .NET Core, please refer to the .NET Tutorial.

We will work through a simple C# example in order to illustrate the use of the Gurobi .NET interface. The example builds a model, optimizes it, and outputs the optimal objective value.

Our example optimizes the following model:

maximize x + y + 2 z    
subject to x + 2 y + 3 z <span>$</span>\leq<span>$</span> 4
  x + y     <span>$</span>\geq<span>$</span> 1
  x, y, z binary  
Note that this is the same model that was modeled and optimized in the C Interface section.


Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.