Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda