I am passing a IList into another class which looks as follows:
public class KundenViewModel
{
public IList<Kunde> _kunden;
/// <summary>
/// Add a list of Kunde to the View
/// </summary>
/// <param name="kunden">A list of Kunde objects&开发者_高级运维lt;/param>
public KundenViewModel(IList<Kunde> kunden)
{
foreach (var k in kunden)
{
var test = k._Name;
_kunden.Add(k);
}
//_kunden.AddRange(kunden);
}
/// <summary>
/// Add one Object of Kunde to the View
/// </summary>
/// <param name="kunde">A Kunde Object</param>
public KundenViewModel(Kunde kunde)
{
_kunden.Add(kunde);
}
}
But at runtime I receive at the Line 14 (_kunden.Add(k);) the error "Object reference not set to an instance of an object." Well I would say the object has never been initialized, but It has been and I also can access the properties for example the line before, there is no error.
Thanks in Advance
Have you initialized _kunden list?
Looks like _kunden is null. Where is it initialized?
You have yet to initialise _kunden. You only declared it atm, meaning that you are currently trying to add k to null.
The error message probably refers to the _kunden collection. It is probably not initialized.
精彩评论