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:
- public class BOSampleBusinessObject
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public string Decription { get; set; }
- }
-
After that I created a list of this object as follows and got data into is using simple ADO.NET:
- 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:
- 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