LINQ

Parsing XML using LINQ:


XElement root = new XElement("Root",
    new XElement("Child1", 1),
    new XElement("Child1", 2),
    new XElement("Child1", 3),
    new XElement("Child2", 4),
    new XElement("Child2", 5),
    new XElement("Child2", 6)
);
IEnumerable<XElement> list = root.XPathSelectElements("./Child2");
foreach (XElement el in list)
    Console.WriteLine(el);


Searching in a list :

var actualparam = from c in YourList
                               where c.Name == "<your search criteria>"
                               select c;


Here, YourList could be any List or class name in which the data is present. The var keyword is used to declare and initialize anonymous types

Or You can search using predicates :

 List<security> lstSelectedUser = lstUsers.Where(n => n.Managerid == userID).ToList();

No comments:

Post a Comment