-1
List<int> num = new List<int>();
    void OnGUI()
    {
        GUI.color = Color.white;

        scrollPos =
            EditorGUILayout.BeginScrollView(scrollPos, true,true,
            GUILayout.ExpandWidth(true), GUILayout.Height(position.height));

        foreach (KeyValuePair<GameObject, string> pair in dictio)
        {
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.ObjectField(pair.Key, typeof(GameObject), true);
            num.Add(EditorGUILayout.TextField(pair.Value).Length);
            

            EditorGUILayout.EndHorizontal();
        }
        GUILayout.EndScrollView();

        window.maxSize = new Vector2(num[], position.height);
    }

after the loop I want to find the highest value from the List num and set it as the window width size.

2
  • use Max ? Commented May 2, 2023 at 12:34
  • Or why even use a list for this? you could simply have a var maxWidth = 0; and then for each iteration do maxWidth = Mathf.Max(maxWidth, EditorGUILayout.TextField(pair.Value).Length); without the need for iterating yet another list ... Commented May 2, 2023 at 12:38

2 Answers 2

0

Did you try int max = num.Max();?

Sign up to request clarification or add additional context in comments.

Comments

0

Can you not just use .Sort() or .OrderBy(x => x) or even .OrderByDescending(x => x) and get the highest value that way?

For example, you could do

int width = num.OrderByDescending(x => x).FirstOrDefault()`

or

int width = num.Max()

or

num.Sort();
num.Reverse();
int width = num.FirstOrDefault();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.