String Contains() - C# Tutorial
C# Course / Strings / String Contains()

String Contains()

BLUF: Mastering String Contains() is essential for building robust applications with the .NET ecosystem. This tutorial provides clear explanations and practical examples to help you understand and apply this C# concept.
Enterprise Development Tip: String Contains()

C# is a powerful, modern language for enterprise solutions. Discover how String Contains() enhances your development workflow in the guide below.

The Contains method in C# is employed to determine if a particular substring exists within a given string. It returns true if the substring is present, and false if it is not found.

Signature

Example

public bool Contains(String str)

Parameters

str: It represents a string object that is utilized to verify the presence within the string it is called upon.

Return

It returns boolean value either true or false.

C# String Contains method Example

Example

using System;  
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
             string s1 = "Hello ";  
             string s2 = "He";
          	 string s3 = "Hi";
             Console.WriteLine(s1.Contains(s2));
             Console.WriteLine(s1.Contains(s3));
             
        }  
    }

Output:

Output

True
False

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience