在C#中,Match和Equals是两个不同的方法,它们的作用和用法也不同。
示例:
string pattern = @"^\d{3}-\d{3}-\d{4}$";
string input = "123-456-7890";
Match match = Regex.Match(input, pattern);
if (match.Success)
{
Console.WriteLine("Input matches the pattern");
}
示例:
string str1 = "hello";
string str2 = "world";
if (str1.Equals(str2))
{
Console.WriteLine("The two strings are equal");
}
总结来说,Match用于字符串匹配,主要用于正则表达式;Equals用于比较对象是否相等,根据对象的值进行比较。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c# yaml和json区别在哪