i have a array type pessoas, and i'm trying to populate it with the user input, it compiles ok, but in the line ///lstp[--cont].salario = Convert.ToDouble(Console.ReadLine());/// i'm getting this error msg after i enter with any input, System.NullReferenceException, any idea on why is returning a null?
static void Main(string[] args)
{
pessoas p = new pessoas();
int cont = 0;
pessoas[] lstp = new pessoas[4];
foreach (var item in lstp)
{
Console.WriteLine("pessoa " + (++cont)+": ");
Console.Write("salario: ");
lstp[--cont].salario = Convert.ToDouble(Console.ReadLine());
Console.Write("\nFilhos: ");
lstp[cont].filhos = Convert.ToInt16(Console.ReadLine());
cont++;
}
p.calculo(lstp);
Console.ReadKey();
}
class pessoas
{
public double salario { get; set; }
public int filhos { get; set; }
}