C# String EndsWith Method Example

In this source code example, we will demonstrate the usage of String.EndsWith() method in C# with an example.

The C# String.EndsWith() method is used to check whether the specified string matches the end of this string or not. If the specified string is found at the end of this string, it returns true otherwise false.

C# String EndsWith Method Example

The following example demonstrates the String.EndsWith() method:
using System;

public class StringDemo
{
    public static void Main(string[] args)
    {
        string s1 = "sourcecodeexamples";
        string s2 = "code";
        string s3 = "examples";
        
        Console.WriteLine(s1.EndsWith(s2));  
        
        Console.WriteLine(s1.EndsWith(s3));  

    }

}

Output:

False
True

Related C# String Examples

References

https://docs.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-6.0


Comments