我有这样添加模型对象列表失败
namespace ConnectBLL.DTO.Response
{
public class CategorySettings
{
public bool NeedsLoginToViewLongText { get; set; }
public bool NeedsLoginToViewAnyDetails { get; set; }
public bool ShowAttachment { get; set; }
public string CategoryPageID { get; set; }
public string TpUrl { get; set; }
}
public class CategorySettingsListResponse
{
public List<CategorySettings> CategorySettingsList { get; set; }
}
}
模型类,我试图将数据添加到它像这样
private readonly CategorySettings cs = new CategorySettings();
CategorySettingsListResponse csr=new CategorySettingsListResponse();
public string GetAllCategorySettings()
{
cs.NeedsLoginToViewLongText = true;
cs.NeedsLoginToViewAnyDetails = false;
cs.ShowAttachment = true;
cs.CategoryPageID = "1";
cs.TpUrl = "url";
csr.CategorySettingsList.Add(cs);
}
但这种失败,并给出了一个错误
Object reference not set to an instance of an object.
有没有人能指出我做错了什么?
如果定义'cs'? – Ofiris
@Ofiris我错过了这个问题。现在添加 – Athul