This question already has an answer here:

Code for my Model in which I want to have a list

namespace stay_calm.Models
{
    public class graph_user
    {
     public  List<int> year { get; set; }
     public  List<int> number{ get; set; }
    }
}

And my Controller Code:

 public ActionResult try_graph_database()
        {
 new graph_user graph = new graph_user();

            int one = 1;
            if(graph.year== null)
            {
                graph.year[0] = one;  // This gives me null pointer exception
            }



return View ();
}

I am trying to add values to my year list< int> but it gives me null pointer, so what is the proper way of doing this? I tried graph.sensors.add() nothing works

Related posts

Recent Viewed