Quering a List using LINQ

As a requirement, I came through a condition where I needed to query a C# list collection using LINQ.
 
The list was a collection of objects. The Object definition is as below:
  1. public class BOSampleBusinessObject  
  2.    {  
  3.        public int ID { getset; }  
  4.        public string Name { getset; }  
  5.        public string Decription { getset; }  
  6.    }  
  7.             
After that I created a list of this object as follows and got data into is using simple ADO.NET:
  1. List<BOSampleBusinessObject> lstBOSampleBusinessObject  = new List<BOSampleBusinessObject>;  
Now, I needed to query this list  on the basis of the Name parameter. It was done in the below manner:
  1. var ouputData = lstBOSampleBusinessObject.Where(x=> x.Name.Equals("Vipul"));  
This gave me the correct queried data in my var object.
 
I can now use it in the way I want.
 
Hope this helped.
 
Thanks
 
Vipul 
Ebook Download
View all
Learn
View all