How many positions do I have in an array?

1

I try to do the following ...

class Nested
     {
         Persona[] Empresa;

         struct Persona
         {
             public string nombre;
             public string apellido1;
             public string apellido2;
             public Fecha fechanacimiento;
         };

         struct Fecha
         {
             public DateTime fechaNacimiento;
         };

         public Nested()
         {
             Empresa = new Persona[100];
         }

         public int Ocupados()
         {
            return Empresa.Count(s => s != null);
        }
}

I get the following error ...

These are tests that I'm doing, I know that the List < > they are much better to do things of this type but I do not know why it does not allow me to compare array positions, which can contain structures of type Persona with null

    
asked by Edulon 11.03.2018 в 16:32
source

1 answer

3

Structures are a type of value that can never be null . You should ask yourself why you are defining a struct and not a class and if it really is what you need.

Define it as a class if you want it to be null .

    
answered by 11.03.2018 / 16:49
source