How can I search a generic list with the Find method?

M

mark4asp

The code is failing on line 266, with the message:

Object reference not set to an instance of an object.

The problem seems to be with 'penFundCon'

Source Error:

L265: List<PensionFundConsultant> PensionFunds =
(List<PensionFundConsultant>)Cache["PensionFunds"];
L266: PensionFundConsultant pfc =
PensionFunds.Find(delegate(PensionFundConsultant penFundCon)
L267: {
L268: return (penFundCon.PensionFundID ==
Convert.ToInt32(ddlPensionFund.SelectedValue));
}
);
lblConsultant.Text = pfc.ConsultantName;
hidConsultantID.Value = pfc.ConsultantID.ToString();
hidConsultantDDL.Value = true.ToString();

==========================================
The PensionFundConsultant looks like this
==========================================

using System;
/// <summary>
/// Summary description for PensionFundConsultant
/// </summary>
public class PensionFundConsultant
{
#region Private Member Variables
private int _pensionFundID = 0;
private string _pensionFundName = "";
private int _consultantID = 0;
private string _consultantName = "";

#endregion

#region Constructors
public PensionFundConsultant()
{

}
public PensionFundConsultant(int pensionFundID, string
pensionFundName, int consultantID, string consultantName)
{
this.PensionFundID = pensionFundID;
this.PensionFundName = pensionFundName;
this.ConsultantID = consultantID;
this.ConsultantName = consultantName;
}

#endregion

#region Public Properties
public int PensionFundID
{
get { return _pensionFundID; }
set { _pensionFundID = value; }
}
public string PensionFundName
{
get { return _pensionFundName; }
set { _pensionFundName = value; }
}
public int ConsultantID
{
get { return _consultantID; }
set { _consultantID = value; }
}
public string ConsultantName
{
get { return _consultantName; }
set { _consultantName = value; }
}
#endregion
}
 
M

mark4asp

The code is failing on line 266, with the message:

Object reference not set to an instance of an object.

This is failing when I do the initial search. If I stick it in a try
catch the 2nd search will work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top