> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Example 12 - C#

## C\#

```csharp theme={null}
using System;
using ZOSAPI;

namespace CSharpStandaloneApplication
{
 class Program
    {
 static void Main(string[] args)
        {
 // Find the installed version of OpticStudio
 bool isInitialized = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize();
 // Note -- uncomment the following line to use a custom initialization path
 //bool isInitialized = ZOSAPI_NetHelper.ZOSAPI_Initializer.Initialize(@"C:\Program Files\OpticStudio\");
 if (isInitialized)
            {
                LogInfo("Found OpticStudio at: " + ZOSAPI_NetHelper.ZOSAPI_Initializer.GetZemaxDirectory());
            }
 else
            {
                HandleError("Failed to locate OpticStudio!");
 return;
            }

            BeginStandaloneApplication();
        }

 static void BeginStandaloneApplication()
        {
 // Create the initial connection class
 ZOSAPI_Connection TheConnection = new ZOSAPI_Connection();

 // Attempt to create a Standalone connection
 IZOSAPI_Application TheApplication = TheConnection.CreateNewApplication();
 if (TheApplication == null)
            {
                HandleError("An unknown connection error occurred!");
 return;
            }

 // Check the connection status
 if (!TheApplication.IsValidLicenseForAPI)
            {
                HandleError("Failed to connect to OpticStudio: " + TheApplication.LicenseStatus);
 return;
            }
 if (TheApplication.Mode != ZOSAPI_Mode.Server)
            {
                HandleError("User plugin was started in the wrong mode: expected Server, found " + TheApplication.Mode.ToString());
 return;
            }

 IOpticalSystem TheSystem = TheApplication.PrimarySystem;

 // creates new directory
 string strPath = System.IO.Path.Combine(TheApplication.SamplesDir, @"API\CS");
            System.IO.Directory.CreateDirectory(strPath);

 // Select 6 wavelengths using a Gaussian Quadrature algorithm
 ZOSAPI.SystemData.IWavelengths sysWave = TheSystem.SystemData.Wavelengths;
            sysWave.GaussianQuadrature(0.45, 0.65, ZOSAPI.SystemData.QuadratureSteps.S6);

 // Define fields using Paraxial Image Height
 ZOSAPI.SystemData.IFields sysField = TheSystem.SystemData.Fields;
            sysField.SetFieldType(ZOSAPI.SystemData.FieldType.ParaxialImageHeight);

 // Change field 1 to be X=1.0 and Y=2.0
 ZOSAPI.SystemData.IField field1 = sysField.GetField(1);
            field1.X = 1.0;
            field1.Y = 2.0;

 // Inserts paraxial lens so there will not be an error when using ParaxialImageHeight
            TheSystem.SystemData.Aperture.ApertureValue = 10;
 ZOSAPI.Editors.LDE.ILDERow s1 = TheSystem.LDE.GetSurfaceAt(1) as ZOSAPI.Editors.LDE.ILDERow;
 ZOSAPI.Editors.LDE.ISurfaceTypeSettings s1_type = s1.GetSurfaceTypeSettings(ZOSAPI.Editors.LDE.SurfaceType.Paraxial) as ZOSAPI.Editors.LDE.ISurfaceTypeSettings;
            s1.ChangeType(s1_type);
            s1.Thickness = 100;

 // Change polarization axis reference to be Y
 ZOSAPI.SystemData.ISDPolarizationData sysPol = TheSystem.SystemData.Polarization;
            sysPol.Method = ZOSAPI.SystemData.PolarizationMethod.YAxisMethod;

 // Add Corning catalog and remove Schott catalog
 ZOSAPI.SystemData.ISDMaterialCatalogData sysCat = TheSystem.SystemData.MaterialCatalogs;
            sysCat.AddCatalog("Corning");
            sysCat.RemoveCatalog("Schott");

 // Add Title and Notes
 ZOSAPI.SystemData.ISDTitleNotes sysTitleNotes = TheSystem.SystemData.TitleNotes;
            sysTitleNotes.Title = "Add here the title";
            sysTitleNotes.Notes = "Add here the notes";

 // As default Files choose: COATING.DAT, SCATTER_PROFILE.DAT, ABG_DATA.DAT
 ZOSAPI.SystemData.ISDFiles sysFiles = TheSystem.SystemData.Files;
            sysFiles.CoatingFile = "COATING.DAT";
            sysFiles.ScatterProfile = "SCATTER_PROFILE.DAT";
            sysFiles.ABgDataFile = "ABG_DATA.DAT";
            TheSystem.SystemData.Files.ReloadFiles();

 // Change Lens Units to Inches
 ZOSAPI.SystemData.ISDUnitsData sysUnits = TheSystem.SystemData.Units;
            sysUnits.LensUnits = ZOSAPI.SystemData.ZemaxSystemUnits.Inches;

 String file = "\\API\\CS\\e12_seq_system_explorer.zos";
            TheSystem.SaveAs(TheApplication.SamplesDir + file);

 // Clean up
            FinishStandaloneApplication(TheApplication);
        }

 static void FinishStandaloneApplication(IZOSAPI_Application TheApplication)
        {
 // Note - TheApplication will close automatically when this application exits, so this isn't strictly necessary in most cases
 if (TheApplication != null)
            {
                TheApplication.CloseApplication();
            }
        }

 static void LogInfo(string message)
        {
 // TODO - add custom logging
            Console.WriteLine(message);
        }

 static void HandleError(string errorMessage)
        {
 // TODO - add custom error handling
 throw new Exception(errorMessage);
        }

    }
}
```
