We can check an instance of a list count() globally
Now create instance in any class & check any list's instance Count();
public class CheckListCount
{
public bool IsOneItemEntry(IEnumerable<dynamic> objEntity)
{
String ErrorMessage="";
bool IsValid = true;
if (objEntity.Count() == 0)
{
IsValid = false;
ErrorMessage = "At least one item must be available.";
}
return IsValid;
}
}
Now create instance in any class & check any list's instance Count();
private CheckListCount _CheckList = new CheckListCount();
List<CommentReceipt> CommentReceiveItem = new List<CommentReceipt>();
foreach (LAB_LDCommentReceipt receipt in ViewData.LdCommentReceiveList)
{
if (receipt.AppStatusID>0)
{
CommentReceiveItem.Add(receipt);
}
}
if (_CheckList.IsOneItemEntry(CommentReceiveItem))
{
// do something
}
Comments
Post a Comment