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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.