The EndsWith() Method is used to check, if a String ends with a particular substring.
public class MyApplication
{
public static void Main(string[] args)
{
string x = "Hello Beautiful World";
if (x.EndsWith("World"))
{
System.Console.WriteLine("The String ends with World");
}
else
{
System.Console.WriteLine("The String does not end with World");
}
}
}
In the above code, we have declared a String Hello Beautiful World and assigned it to a variable x.
string x = "Hello Beautiful World";
-Method1.png)
And we have checked if the String, Hello Beautiful World ends with the substring World.
if (x.EndsWith("World"))
{
System.Console.WriteLine("The String ends with World");
}
else
{
System.Console.WriteLine("The String does not end with World");
}And in this case the String, substring Hello Beautiful World ends with the substring World
And thus we get the below output.