---
tags:
    - "Max"
    - "Highest"
    - "Biggest"
    - "Greatest"
    - "List"
    - "Array"
---

# Maximum

[Collections](index.md) / **Maximum**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

The largest value found in a collection read as numbers

## Parameters

| Name | Description |
| :--- | :---------- |
| Collection | The collection whose largest item is returned |

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Maximum")]
    [Category("Collections/Maximum")]

    [Description("The largest value found in a collection read as numbers")]
    [Image(typeof(IconStack), ColorTheme.Type.Teal, typeof(BadgeArrowUp))]

    [Parameter("Collection", "The collection whose largest item is returned")]

    [Keywords("Max", "Highest", "Biggest", "Greatest", "List", "Array")]

    [Serializable]
    public class TypeNumberCollectionMax : TypeNumber
    {
        [SerializeField] private GetCollection m_Collection = new GetCollection();

        public override double Get(Args args)
        {
            using Args scoped = Args.Get(args);

            int count = this.m_Collection.Capture(scoped);
            if (count == 0) return 0f;

            double max = 0f;
            bool hasValue = false;

            for (int i = 0; i < count; ++i)
            {
                if (!ArgsCollectionParameters.TryGetItem(this.m_Collection, scoped, i, out double item)) continue;

                max = hasValue ? Math.Max(max, item) : item;
                hasValue = true;
            }

            return max;
        }

        public override string ToString()
        {
            return $"Max of {this.m_Collection}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}

```

