My method returns a response object which contains a list of objects.
public class GetAccountsListResponse
{
    public List<AccountsList> Accounts { get; set; }
}
public class AccountsList
{
    public string AccountId { get; set; }
    public string AccountName { get; set; }
}
I tried something like this, but im getting null refernce exception :
public GetAccountsListResponse GetAccountsList()
    {
        AccountRepository objRepo = new AccountRepository();
        GetAccountsListResponse res = new GetAccountsListResponse();
        List<Account> lstAccnts = new List<Account>();
        lstAccnts = objRepo.GetAccountsFromRepo();
        foreach (var item in lstAccnts)
        {
            res.Accounts = new List<AccountsList>();
            res.Accounts.ForEach(c => c.AccountId = item.AccountId);    
        }
        return res;
    }
Please help me to fix the issue.
 
    