I need to get all the animals available in the data base and to display it in console. I have tried the below code but I am getting "NullReference Exception"(Object reference not set to an instance of an object.). Let me know whether I am following the correct approach or not.

**Code:**

```
static void Main(string[] args)
{
    AnimalListDao objDao = new AnimalListDao();
    objDao.getPetAnimalList();
    AnimalList objAnim = new AnimalList();
    foreach(var item in objAnim.animalListObj)     // Null Reference Exception occurs here
    {
         Console.WriteLine(item.Animals);
         Console.ReadLine();
    }
}

```

**Business Class:**

```
class petAnimals
    {
        public string Animals { get; set; } 
    }

    class AnimalList
    {
        private List<petAnimals> _animalListObj;
        public List<petAnimals> animalListObj
        {
            get
            {
                return _animalListObj;
            }
            set
            {
                _animalListObj = value;
            }
        }
    }

    class AnimalListDao
    {
        AnimalList obAni = new AnimalList();
        petAnimals objAnimal = null;
        public void getPetAnimalList()
        {
            string commandStr = "select petAnimals from animal";
            string conStr = "Data Source=localhost;Initial Catalog=PetTable;UserId=root;Password=;";
            List<petAnimals> objList = new List<petAnimals>();
            MySqlConnection con = new MySqlConnection(conStr);
            MySqlCommand cmd = new MySqlCommand(commandStr,con);
            MySqlDataAdapter dap = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            dap.Fill(ds);
            foreach (DataRow dss in ds.Tables[0].Rows)
            {
                objAnimal = new petAnimals();
                objAnimal.Animals = dss["petAnimals"].ToString();
                objList.Add(objAnimal);
            }
            obAni.animalListObj = objList;
        }
    }

```