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