# Contain

## ShouldContain

```cs
var mrBurns = new Person { Name = "Mr.Burns", Salary = 3000000 };
var kentBrockman = new Person { Name = "Kent Brockman", Salary = 3000000 };
var homer = new Person { Name = "Homer", Salary = 30000 };
var millionaires = new List<Person> { kentBrockman, homer };
millionaires.ShouldContain(mrBurns);
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/EnumerableShouldContainExamples.ShouldContain.codeSample.approved.cs#L1-L5) | [anchor](#snippet-EnumerableShouldContainExamples.ShouldContain.codeSample.approved.cs)

**Exception**

```
millionaires
    should contain
Mr.Burns
    but was actually
[Kent Brockman, Homer]
```

### With Predicate

```cs
var homer = new Person { Name = "Homer", Salary = 30000 };
var moe = new Person { Name = "Moe", Salary = 20000 };
var barney = new Person { Name = "Barney", Salary = 0 };
var millionaires = new List<Person> { homer, moe, barney };
millionaires.ShouldContain(m => m.Salary > 1000000);
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/EnumerableShouldContainExamples.ShouldContain_Predicate.codeSample.approved.cs#L1-L5) | [anchor](#snippet-EnumerableShouldContainExamples.ShouldContain_Predicate.codeSample.approved.cs)

**Exception**

```
millionaires
    should contain an element satisfying the condition
(m.Salary > 1000000)
    but does not
```

## ShouldNotContain

```cs
var homerSimpson = new Person { Name = "Homer" };
var homerGlumplich = new Person { Name = "Homer" };
var lenny = new Person { Name = "Lenny" };
var carl = new Person { Name = "carl" };
var clubOfNoHomers = new List<Person> { homerSimpson, homerGlumplich, lenny, carl };
clubOfNoHomers.ShouldNotContain(homerSimpson);
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/EnumerableShouldNotContainExamples.ShouldNotContain.codeSample.approved.cs#L1-L6) | [anchor](#snippet-EnumerableShouldNotContainExamples.ShouldNotContain.codeSample.approved.cs)

**Exception**

```
clubOfNoHomers
    should not contain
Homer
    but was actually
[Homer, Homer, Lenny, carl]
```

### With Predicate

```cs
var mrBurns = new Person { Name = "Mr.Burns", Salary = 3000000 };
var kentBrockman = new Person { Name = "Homer", Salary = 3000000 };
var homer = new Person { Name = "Homer", Salary = 30000 };
var millionaires = new List<Person> { mrBurns, kentBrockman, homer };
millionaires.ShouldNotContain(m => m.Salary < 1000000);
```

[snippet source](https://github.com/shouldly/shouldly/blob/master/src/DocumentationExamples/CodeExamples/EnumerableShouldNotContainExamples.ShouldNotContain_Predicate.codeSample.approved.cs#L1-L5) | [anchor](#snippet-EnumerableShouldNotContainExamples.ShouldNotContain_Predicate.codeSample.approved.cs)

**Exception**

```
millionaires
    should not contain an element satisfying the condition
(m.Salary < 1000000)
    but does
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shouldly.org/documentation/enumerable/contain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
