# Cloud Optimization v1 API - Class DistanceLimit (2.7.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.7.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/latest/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.6.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.6.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.5.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.5.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.4.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.3.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.3.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.2.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.1.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [2.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/2.0.0/Google.Cloud.Optimization.V1.DistanceLimit)
- [1.0.0-beta01](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/1.0.0-beta01/Google.Cloud.Optimization.V1.DistanceLimit)

    public sealed class DistanceLimit : IMessage<DistanceLimit>, IEquatable<DistanceLimit>, IDeepCloneable<DistanceLimit>, IBufferMessage, IMessage

Reference documentation and code samples for the Cloud Optimization v1 API class DistanceLimit.

A limit defining a maximum distance which can be traveled. It can be either
hard or soft.

If a soft limit is defined, both `soft_max_meters` and
`cost_per_kilometer_above_soft_max` must be defined and be nonnegative.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> DistanceLimit

## Implements

[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[DistanceLimit](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/latest/Google.Cloud.Optimization.V1.DistanceLimit), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[DistanceLimit](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/latest/Google.Cloud.Optimization.V1.DistanceLimit), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[DistanceLimit](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/latest/Google.Cloud.Optimization.V1.DistanceLimit), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html)

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Cloud.Optimization.V1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/latest/Google.Cloud.Optimization.V1)

## Assembly

Google.Cloud.Optimization.V1.dll

## Constructors

### DistanceLimit()

    public DistanceLimit()

### DistanceLimit(DistanceLimit)

    public DistanceLimit(DistanceLimit other)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `other` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Optimization.V1/latest/Google.Cloud.Optimization.V1.DistanceLimit` |

## Properties

### CostPerKilometerAboveSoftMax

    public double CostPerKilometerAboveSoftMax { get; set; }

Cost per kilometer incurred if distance is above `soft_max_meters` limit.
The additional cost is 0 if the distance is under the limit, otherwise the
formula used to compute the cost is the following:

      (distance_meters - soft_max_meters) / 1000.0 *
      cost_per_kilometer_above_soft_max.

The cost must be nonnegative.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.double` |   |

### CostPerKilometerBelowSoftMax

    public double CostPerKilometerBelowSoftMax { get; set; }

Cost per kilometer incurred, increasing up to `soft_max_meters`, with
formula:

      min(distance_meters, soft_max_meters) / 1000.0 *
      cost_per_kilometer_below_soft_max.

This cost is not supported in `route_distance_limit`.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.double` |   |

### HasCostPerKilometerAboveSoftMax

    public bool HasCostPerKilometerAboveSoftMax { get; }

Gets whether the "cost_per_kilometer_above_soft_max" field is set

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### HasCostPerKilometerBelowSoftMax

    public bool HasCostPerKilometerBelowSoftMax { get; }

Gets whether the "cost_per_kilometer_below_soft_max" field is set

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### HasMaxMeters

    public bool HasMaxMeters { get; }

Gets whether the "max_meters" field is set

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### HasSoftMaxMeters

    public bool HasSoftMaxMeters { get; }

Gets whether the "soft_max_meters" field is set

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### MaxMeters

    public long MaxMeters { get; set; }

A hard limit constraining the distance to be at most max_meters. The limit
must be nonnegative.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int64` |   |

### SoftMaxMeters

    public long SoftMaxMeters { get; set; }

A soft limit not enforcing a maximum distance limit, but when violated
results in a cost which adds up to other costs defined in the model,
with the same unit.

If defined soft_max_meters must be less than max_meters and must be
nonnegative.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int64` |   |