Home and Learn: C# NET Course

The Contains Method In C# .Net

The contains method can be used if you want to check if a string contains certain characters. It's fairly simple to use. Here's an example:

The Contains method in action

After the contains method, you type a pair of round brackets. In between the round brackets, you type the text you're checking for. In our code, we're using an if statement. If it's true that the string contains a "-" character, then some code can be executed.


A more complicated, and probably more useful, method that you'll need to know about is called IndexOf. That's the next lesson.

back to the c# net contents page


Buy the Book of this Course

Email us: enquiry at homeandlearn.co.uk