Ancestors

The Ancestors operator can be called on a sequence of nodes and returns a sequence containing the ancestor elements of each source node.

Prototypes

The Ancestors operator has two prototypes.

Example. The First Ancestors Prototype
public static IEnumerable<XElement> Ancestors<T> (
  this IEnumerable<T> source
) where T : XNode

This version of the operator can be called on a sequence of nodes, or objects derived from XNode. It returns a sequence of elements containing the ancestor elements of each node in the source sequence.

Example. The Second Ancestors Prototype
public static IEnumerable<XElement> Ancestors<T> (
  this IEnumerable<T> source,
  XName name
) where T : XNode

This version is like the first, except a name is passed and only ...

Get Pro LINQ: Language Integrated Query in C# 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.