Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
Get Minimum and Maximum value in a list

I am using adding two variables in my SetValues list. The variables are Position and Value. Now I want to check in my List what is the maximum Value and what is the minimum Value (For only "Value"). Now when I do the following:

[Serializable]
    public struct SetValues {
        public float Position;
        public float Value;
    }

    public List<SetValues> setValues;

void Start () {
        Debug.Log (setValues.Value.Min ());
    }

It says that "does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type could be found". The only reason I want to use List is to avoid iteration that should be done when using an array. But what is the mistake am I doing here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have at your disposition the IEnumerable extensions provided in the Linq namespace. It is just a simple line of code for min and another one for max

var minV = setValues.Min(x => x.Value);
var maxV = setValues.Max(x => x.Value);

However, you cannot avoid an iteration over the list. The Min and Max extensions contains an hidden loop that seeks the value requested.

Your code cannot work because setValues is a list of SetValues objects. It is confusing for us with just a letter different by its case but it is a clear error for the compiler that complains about it. I suggest to find a different name for the class or a different name for the list variable

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!