EndsWith()C#中的方法用于检查当前字符串实例的结尾是否与指定的字符串匹配。
以下是语法-
public bool EndsWith(string str)
上面的str参数是要比较的字符串。
现在让我们看一个实现该EndsWith()方法的示例-
using System;
public class Demo{
   public static void Main(){
      bool val;
      string str = "demo$";
      val = str.EndsWith("$");
      Console.WriteLine("Return Value = "+val.ToString());
   }
}输出结果
这将产生以下输出-
Return Value = True
现在让我们来看另一个实现该EndsWith()方法的示例-
using System;
public class Demo{
   public static void Main(){
      bool val;
      string str = "mytext@";
      val = str.EndsWith("#");
      Console.WriteLine("Return Value = "+val.ToString());
   }
}输出结果
这将产生以下输出-
Return Value = False