I have this foreach loop in c#, since i am new to c#, i was wondering if this can be written shorter (have the condition part of the loop

```
foreach (PagerPageFilterInformation filter in PageFilterInformation)
{
    if (filter.Ancestor == myParent)
    {
        DoSomething()...//Using filter
        break;
    }
}

```

I tried doing :

```
PagerPageFilterInformation filter = PageFilterInformation.FirstOrDefault(filter => filter.Ancestor == myParent);
if(filter != null)
{
DoSomething()...}

```

But it didnt work. could it be because the class:

```
PagerPageFilterInformation

```

Inherits from the class :

```
PageFilterInformation

```

?