Delegate Using in Generic List

Tijut2k
Posted by Tijut2k under C# category on | Points: 40 | Views : 3143
1) Using Delegate to Check the item in the Generic list
private bool CheckItemExistence(InspectionCheckList chkList)
{
List<InspectionCheckList> insChkList = new List<InspectionCheckList>();
insChkList = (List<InspectionCheckList>)Session[SessionVariable.CheckList];
if (insChkList != null)
{
if (insChkList.Exists(delegate (InspectionCheckList o) {return o.CodeID == chkList.CodeID;}))
return true;
else
return false;
}
else
return false;
}


2)Using Delegate to Find the Item in the Generic list then remove from the Generic list
 private void RemoveFromLIst(int itemId)
{
List<InspectionCheckList> insChkList = new List<InspectionCheckList>();
insChkList = (List<InspectionCheckList>)Session[SessionVariable.CheckList];
InspectionCheckList desiredObject =
insChkList.Find(delegate(InspectionCheckList o) { return o.CodeID == itemId; });

insChkList.Remove(desiredObject);
//grdSaveItems.DataSource = insChkList;
//grdSaveItems.DataBind();
Session[SessionVariable.CheckList] = insChkList;
}

Comments or Responses

Posted by: Nishithraj on: 5/9/2011 Level:Bronze | Status: [Member] | Points: 10
Hi Tiju,

What's the advantage if we are doing this through delegates? Can you explain it?
Posted by: Tijut2k on: 5/10/2011 Level:Starter | Status: [Member] | Points: 10
Posted by: T.saravanan on: 5/10/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi,

Nice try.But post your code inside the code tag.

Login to post response