0

Пишет ошибку при добавлении объекта в список "Ссылка на объект не указывает на экземпляр объекта." Как быть?

var countryList = new otherCountryObj();
countryList.Country = "RU";
countryList.QWE = "4000234234928305928";

model.rezidentOtherCountry.country.Add( countryList );

public class rezidentOtherCountry
{
    public bool? isRezidentOtherCountry { get; set; }
    public List<otherCountryObj> country;
}

public class otherCountryObj
{
   public string Country { get; set; }
   public string QWE{ get; set; }
}
jScheq
  • 11

1 Answers1

1

В класс нужно добавить, например конструктор в кот. проинициализировать коллекцию

public class rezidentOtherCountry
{
    public bool? isRezidentOtherCountry { get; set; }
    public List<otherCountryObj> country;

    public rezidentOtherCountry()
    {
        country = new List<otherCountryObj>();
    }
}
Bulson
  • 9,411