C# globally check List instance's item count

 We can check an instance of a list count() globally


 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  
          }  

Popular posts from this blog

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report